Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!tut.cis.ohio-state.edu!ucbvax!hplabs!hpfcso!hpldola!patch From: patch@hpldola.HP.COM (Pat Chkoreff) Newsgroups: comp.lang.c++ Subject: Re: default arg handling Message-ID: <11430020@hpldola.HP.COM> Date: 12 Mar 90 18:28:43 GMT References: <1116@xyzzy.UUCP> Organization: HP Elec. Design Div. -ColoSpgs Lines: 51 / hpldola:comp.lang.c++ / shap@delrey.sgi.com (Jonathan Shapiro) / 4:13 pm Mar 10, 1990 / > Also, What should your proposal do when it sees: > > int i = 0; > int j = 1; > extern void bar(int x = i + j); > > main() > { > int j = 2; > > bar(); > } As Mark Langley has pointed out, the supplying of default arguments should be thought of as the responsibility of the caller, not part of the function definition. So perhaps the example above should be equivalent to the following, which is valid and comprehensible (albeit reprehensible): int i = 0; int j = 1; extern void bar(int); void bar() { return bar(i+j); } main() { int j = 2; bar(); } Of course, the definition of bar() can be inline'd and/or static'ed, and the "return" is not strictly needed in the body, but that's irrelevant. Perhaps if the last formal argument of a function has a default value, then the compiler should always generate a dummy (inline) function without that argument which simply calls the other function with the appropriate default value. Then the meaning of C++ would be as well-founded as that of C++ without default arguments. BTW, this is the standard way of modeling default arguments in languages which do not support them but do support overloading (esp. Prolog). My apologies if this proposal has already been discussed. Patrick Chkoreff 719-590-5983 {hpfcla,hplabs}!hpldola!patch