Path: utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!samsung!aplcen!haven!uflorida!mephisto!mcnc!rti!xyzzy!bigbird.rtp.dg.com!langley From: langley@bigbird.rtp.dg.com (Mark L Langley) Newsgroups: comp.lang.c++ Subject: default arguments Message-ID: <820@xyzzy.UUCP> Date: 5 Mar 90 14:23:17 GMT Sender: usenet@xyzzy.UUCP Reply-To: langley@bigbird.rtp.dg.com (Mark L Langley) Organization: Data General Corporation, Research Triangle Park, NC Lines: 46 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 I intend to propose this as a change in ANSI C++, and have already proposed it to AT&T in private correspondance. Mark Langley langley@dg-rtp.dg.com