Topic: Default argument implementation survey


Author: wmm@world.std.com (William M. Miller)
Date: Thu, 10 Nov 1994 12:19:47 GMT
Raw View
It has been pointed out to me that file5.C and file9.C have an error
that is unrelated to the default argument question: in the lines in
which a function-style cast is used (e.g., FP(f)(10)), this should
actually be parsed as a declaration with redundant parentheses instead
of a function invocation.  To repair the problem, use the old-style
cast syntax -- ((FP) f)(10).  (Interestingly enough, a majority of
the compilers tested so far have not detected the error, so maybe
I don't feel *too* bad. :-)

Thanks to Jason Merrill of Cygnus Support for this correction.
--
William M. Miller, wmm@setech.com, wmm@world.std.com
Software Emancipation Technology, Inc.,    +1 (617) 466-8600
--
William M. Miller, wmm@setech.com, wmm@world.std.com
Software Emancipation Technology, Inc.,    +1 (617) 466-8600




Author: wmm@world.std.com (William M. Miller)
Date: Wed, 9 Nov 1994 23:56:05 GMT
Raw View
X3J16/WG21 has just informally adopted a resolution to restrict default
argument declarations to function declarations only -- that is, not to
allow default arguments in typedefs, function pointers, references to
functions, and member function pointers.  The formal vote on this
resolution will come Friday morning, November 11.  In preparation for
that vote, I thought it would be helpful to survey existing practice to
see how many implementations currently support these features that would
be removed.  To that end, I have created a very small test suite (at the
end of this message) that tests whether the implementation supports
various uses of default arguments.  If you have ten minutes or so that
you wouldn't mind devoting to this research, I would be very grateful if
you could run the suite and report the results to me via email (post,
too, if you like) by noon, Thursday if possible and certainly no later
than Thursday night.  If you have strong feelings about whether this
restriction is a good or bad idea, I'd be interested in those, also.

I've attached a form that can be filled out and emailed back to me.  It
asks for the compiler, platform (MS-DOS, Sun Solaris, etc.), and version,
as well as whether the test successfully compiled and, if so, whether it
successfully executed.  (Successful execution prints two lines, "10 5"
and "20 5", for tests 1 and 9, and one line, "10 5" for all other tests.)
Please distinguish between failure to compile because of not supporting
the particular use of default arguments and failure to compile for other
reasons; for instance, gcc 2.5.8 does not support references to functions
and hence fails to compile test4.C, but that's different from its failure
to compile test1.C because it doesn't allow adding extra defaults in
subsequent redeclarations of the function.

The only data points I currently have are for gcc 2.5.8 and the Edison
Design Group compiler version 2.19, both for SGI Irix.  Any and all other
C++ implementations are welcome.  Thanks very much for your help.  I will
summarize the results for this group, although possibly not until the
weekend.

-- William M. Miller

==========================================================================

TEST RESULTS:

Compiler, version, and platform:

Test        Compiled successfully?          Executed successfully?

file1

file2

file3

file4

file5

file6

file7

file8

file9

==========================================================================

//-------------------------------------
// file1.C
// "Standard" usage: function declarations, including extra defaults in
// a subsequent declaration

#include <stdio.h>
int main() {
    extern void f(int,int=5);
    f(10);
    extern void f(int=20,int);
    f();
}
void f(int i, int j) { printf("%d %d\n", i, j); }

//-------------------------------------
// file2.C
// Usage with function pointers

#include <stdio.h>
extern void f(int,int);
void (*fp)(int,int=5) = &f;
int main() {
    fp(10);
}
void f(int i, int j) { printf("%d %d\n", i, j); }

//-------------------------------------
// file3.C
// Usage with member function pointers

#include <stdio.h>
struct X { void f(int i, int j) { printf("%d %d\n", i, j); } };
void (X::*mfp)(int,int=5) = &X::f;
int main() {
    X x;
    (x.*mfp)(10);
}

//-------------------------------------
// file4.C
// Usage with function references

#include <stdio.h>
extern void f(int,int);
void (&fr)(int,int=5) = f;
int main() {
    fr(10);
}
void f(int i, int j) { printf("%d %d\n", i, j); }

//-------------------------------------
// file5.C
// Usage with typedefs in cast expressions

#include <stdio.h>
extern void f(int,int);
void (*fp)(int,int) = &f;
int main() {
    typedef void (*F)(int,int=5);
    F(fp)(10);
}
void f(int i, int j) { printf("%d %d\n", i, j); }

//-------------------------------------
// file6.C
// Usage with typedefs in declarations of function pointers

#include <stdio.h>
extern void f(int,int);
typedef void (*F)(int,int=5);
int main() {
    F fp = &f;
    fp(10);
}
void f(int i, int j) { printf("%d %d\n", i, j); }

//-------------------------------------
// file7.C
// Usage with typedefs in member function pointer casts

#include <stdio.h>
struct X { void f(int i, int j) { printf("%d %d\n", i, j); } };
typedef void (X::*MFP)(int,int=5);
void (X::*mfp)(int,int) = &X::f;
int main() {
    X x;
    (x.*MFP(mfp))(10);
}

//-------------------------------------
// file8.C
// Usage in typedefs in declarations of member function pointers

#include <stdio.h>
struct X { void f(int i, int j) { printf("%d %d\n", i, j); } };
typedef void (X::*MFP)(int,int=5);
int main() {
    MFP mfp = &X::f;
    X x;
    (x.*mfp)(10);
}

//-------------------------------------
// file9.C
// Usage of typedefs supplying extra defaults in subsequent declarations

#include <stdio.h>
extern void f(int,int);
void (*fp)(int,int) = &f;
int main() {
    typedef void (*FP)(int,int=5);
    FP(fp)(10);
    typedef void (*FP)(int=20,int);
    FP(fp)();
}
void f(int i, int j) { printf("%d %d\n", i, j); }

--
William M. Miller, wmm@setech.com, wmm@world.std.com
Software Emancipation Technology, Inc.,    +1 (617) 466-8600
--
William M. Miller, wmm@setech.com, wmm@world.std.com
Software Emancipation Technology, Inc.,    +1 (617) 466-8600