sullivan@june.cs.washington.edu (Kevin Sullivan) (02/24/89)
Suppose foo1 is a class and foo2 a subclass. Both have constructors taking (...) as an argument list. I want the constructor for foo2 to call the one for foo1 PASSING THE SAME PARAMETERS AS PASSED TO FOO2. Is there a way to "pass on" a variable argument list like this?
rfg@riunite.ACA.MCC.COM (Ron Guilmette) (02/27/89)
In article <7375@june.cs.washington.edu> sullivan@june.cs.washington.edu (Kevin Sullivan) writes: > >Suppose foo1 is a class and foo2 a subclass. Both have constructors taking >(...) as an argument list. I want the constructor for foo2 to call the >one for foo1 PASSING THE SAME PARAMETERS AS PASSED TO FOO2. Is there a >way to "pass on" a variable argument list like this? I have a related question. Are the c++ language lawyers on-line? Is Bjarne listening? I have recently written a sort of a tool to protoize old-style C code so that it can be eaten up by most self-respecting C++ compilers/translators. Now before I get inundated with requests for copies, let me stress that it is incomplete and it still has some serious problems. Anyway, I'd like to fix it up so that it understands (and does something intelligent with) varargs functions. But there seems to be a catch... Apparently, (when using GNU stuff at least), if you want a varargs function you have to write the function definition like so: #include <varargs.h> int my_func (va_alist) va_dcl { va_list ap; ... } Well, after preprocessing, this comes out to: int my_func (__builtin_va_alist) int __builtin_va_alist; { ... } I assume that this output would be approximately the same for other (i.e. non-GNU) varargs implementations also. Now if you do a simple-minded change to prototype form, you get: int my_func (int __builtin_va_alist) ... This is no good beacuse (in C++ and ANSI C) you will get errors on all of the calls to my_func() which pass anything other than a single int actual parameter. So what do you? You try this instead: int my_func (int __builtin_va_alist, ...) ... But that is still no good, because the compiler will now insist that the first actual parameter in all calls is an int. So instead you consider: int my_func (...) But I believe that ANSI C says that you can't do that because it insists that there must be a comma before the elipsis (i.e. the ...). I guess that ANSI C is trying to force us to put in at least one leading non-vararg parameter for each function. So this whole story raises several questions. Generally, how are you "supposed" to do varargs in C++? Do we just copy the ANSI C <varargs.h> mechanism? Does C++ (unlike ANSI C) permit you to have functions which have *no* leading strictly type-matched formal arguments, or must you have at least one (like ANSI C)? Oh yes... and we shouldn't forget the original question. Just how do you use your varargs within your varargs function? // Ron Guilmette - MCC - Experimental (parallel) Systems Kit Project // 3500 West Balcones Center Drive, Austin, TX 78759 - (512)338-3740 // ARPA: rfg@mcc.com // UUCP: {rutgers,uunet,gatech,ames,pyramid}!cs.utexas.edu!pp!rfg -- // Ron Guilmette - MCC - Experimental (parallel) Systems Kit Project // 3500 West Balcones Center Drive, Austin, TX 78759 - (512)338-3740 // ARPA: rfg@mcc.com // UUCP: {rutgers,uunet,gatech,ames,pyramid}!cs.utexas.edu!pp!rfg