var args

Dave Sherman dave at utcsrgv.UUCP
Sun Oct 16 18:43:07 AEST 1983


Charlie Martin (duke!crm) asks how to implement variable arguments.
In C or on a particular machine? As Henry Spencer points out, it's not
portable and therefore not strictly valid C. However, on a PDP-11
or VAX, you can have the routine

routine(firstarg)
	int *firstarg;
{
	int **argptr;
	argptr = &firstarg;
	...
	argptr++;
	...
}

and refer to *argptr to mean your arguments, **argptr if you want
the character it points to, etc. I have several programs which do
this sort of thing. It's obviously not guaranteed to be portable
to other machines.

It is a useful construct, though, and it seems quite likely that
for any given machine you want to take such code to, you can figure
out what needs doing. Those arguments have to get passed somehow,
so although the incrementing might be different the same basic
technique should continue to work.


Dave Sherman
Toronto
-- 
 {cornell,decvax,ihnp4,linus,utzoo,uw-beaver}!utcsrgv!lsuc!dave



More information about the Comp.lang.c mailing list