Var args: a warning

Mike Edmonds mikee at tektronix.UUCP
Wed Nov 9 18:20:22 AEST 1983


I have seen some advocate using the following code:

foo(fmt,arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9)
char	*fmt;
int	arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9;
{
	/* code, of course */
}

This will work fine on a vax. But I ran into trouble with code like
this when porting dump to an 11/45 and 11/70. If one of your arguments
is a long, as in "foo("d is %ld\n", (long)d)" then you can run into
problems, because of course a long will take *two* of those "int"
spots you reserved. Which makes any arguments following a long all
pretty darn useless, unless you have a pretty specific routine that
knows the 4th argument will always be a long.

It will also confuse you when this happens to be part of your
error detection routine and you rely on accurate output for
debugging!

Rick Lindsley
richl at tektronix
...!tektronix!richl



More information about the Comp.lang.c mailing list