A stupid way to do variable # of arguments?
Tom Haapanen [DCS]
haapanen at watdcsu.UUCP
Thu Aug 23 04:11:03 AEST 1984
<.^.>
I missed a part of the discussion on variable arguments, so maybe my
idea isn't new. Even more likely it's awkward and maybe even
impossible. However, here goes:
- Specify a reserved word, maybe `varargs'.
- When you wish to call a variable argument function, do something
like:
int i, j;
float x, y;
long l;
...
foo(varargs, i, x, l, y, ..)
- When you declare foo, do:
foo(argp, argv)
char *argp;
char *argv[];
{ ...
- OK, so what will happen here is that the 'varargs' tells 'C' that
this is a special case. What 'C' will do upon calling the function is
set up an array of pointers to the parameters (in argv), as well as a
descriptor string (in argp). The argp string could be of printf/scanf
type, or it could just be a string of single character descriptors
(f=float, d=double, i=int, l=long, c=char). Naturally, the called
function would stilll have to do some processing to pull out the
parameters, but it would be easier than it is now. You'd also have to
typecast each element of the pointer array, I guess.
Can anybody tell me (preferably by mail) why this would never work
(besides being clumsy)? Thanks.
Tom Haapanen
University of Waterloo
{allegra,decvax,ihnp4}!watmath!watdcsu!haapanen
-----
I never claimed I understood anything...
More information about the Comp.lang.c
mailing list