passing variable numbers of arguments
Doug Gwyn
gwyn at smoke.BRL.MIL
Fri Jan 13 15:56:12 AEST 1989
In article <11410 at haddock.ima.isc.com> karl at haddock.ima.isc.com (Karl Heuer) writes:
>... given this information, the code ... is portable.
No it isn't!! Apart from the obvious slip of picking up an int where
a long was required (which can be fixed), your use of sizeof to adjust
the byte count is flawed, because sizeof doesn't take into account
alignment requirements of the arguments, which can (and sometimes do)
differ from those of array members. To make this work portably, you
would have to require implementations to provide at least one more
va_ function, but what's the point? By that time, the postulated
utility of an argument byte count has been lost under a barrage of
details.
By the way, the alternate idea of casting argument addresses to
(char *) then subtracting them to count bytes fails due to not
knowing in advance what the type of the next argument is. There may
be room for another argument of one type, but not of another type,
and unless you know more than byte counts you cannot determine
whether or not to pick up another argument.
More information about the Comp.lang.c
mailing list