shane%mishka@RAND.ORG (Darrell) (12/12/90)
How would one use va_start when no formal arguments are specified in
the argument list? For example suppose I wanted to write a function
print_strs which would take an arbitrary number strings, terminated by
a null string, and print them to cout.
void print_strs(...)
{
va_list ap;
va_start(ap, ???); // what arg should be used in place of ???
while( 1 ) {
char *sp = va_arg( ap, char* );
if ( !sp ) break;
cout << sp << "\n";
}
va_end( ap );
}
This is not the best example since there is no compelling reason not
to define print_strs with the argument list ( char *sp1 ... ) and use
sp1 in place of ???. However, I do have a real need for a virtual
member function with an ( ... ) argument list.
Thanks,
Darrell Shaneglenn@huxley.huxley.bitstream.com (Glenn P. Parker) (12/14/90)
In article <9012112222.AA23214@mishka.rand.org>, shane%mishka@RAND.ORG (Darrell) writes: > How would one use va_start when no formal arguments are specified in > the argument list? Varadic functions _must_ have at least one non-varadic argument. The premise is (sort of) that you need at least one argument to tell you how many other arguments to expect. Although you could communicate that information through some other mechanism (e.g. global or member variable), it is simply not supported by <stdarg.h>. -- Glenn P. Parker glenn@bitstream.com Bitstream, Inc. uunet!huxley!glenn 215 First Street BIX: parker Cambridge, MA 02142-1270