Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!uwm.edu!zaphod.mps.ohio-state.edu!brutus.cs.uiuc.edu!jarthur!uci-ics!rfg From: rfg@ics.uci.edu (Ronald Guilmette) Newsgroups: comp.lang.c++ Subject: Re: default arguments Message-ID: <25F8CCEE.9928@paris.ics.uci.edu> Date: 10 Mar 90 09:46:23 GMT References: <820@xyzzy.UUCP> Reply-To: rfg@ics.uci.edu (Ronald Guilmette) Organization: UC Irvine Department of ICS Lines: 59 In article <820@xyzzy.UUCP> langley@bigbird.rtp.dg.com (Mark L Langley) writes: > > >Ron Guilmette replies to article <4800087@m.cs.uiuc.edu> nelson@m.cs.uiuc.edu > >> >> void bill (int b = printf ("default")) {}; >> >>(That is to say that we can assume that if length is not supplied, then the > > passed data is actually a string.) >> >>But it gets upset since "data" is not yet defined/in that scope. Is there >> a way to get around this??? > >// No. A default value expression for a formal parameter can be any kind of >// expression (including function calls) and it can be arbitrarily complex, >// but the expression has to be valid IN THE CONTEXT where it appears (just >// like all other expressions). > ... >// Ron Guilmette (rfg@ics.uci.edu) > > >Ah, not so... but I concur insomuch as I think it *should* be true... > >It is not *IN THE CONTEXT*, as rfg asserts, rather it must be legal outside >of any local context. In other words, Cfront gathers up the context at a >global scope and uses only that global context. Sad but true consider this... > > extern "C" { extern printf(...); }; > > void bar(int x=i+j) { > printf("%d\n", x); > } > > main() { > int i=20, j=30; > bar(); > } > "default.c", line 3: error: i undefined > "default.c", line 3: error: j undefined > "default.c", line 3: error: + of void* > 3 errors Mark, you have obviously misconstrued what I said. You are considering the context in which the default value expression actually comes into play (i.e. at a call point). The point at which a default expression comes into play is obviously different from the point in the text where it actually appears. >I intend to propose this as a change in ANSI C++, and have already >proposed it to AT&T in private correspondance. If you are suggesting that the default expressions be semantically evaluated in the context(s) in which they come into play, think again. The difficulty of implementing such a treatment far outweighs the usefulness of having such a treatment. // Ron Guilmette (rfg@ics.uci.edu) // C++ Entomologist // Motto: If it sticks, force it. If it breaks, it needed replacing anyway.