Grabbing "n" arguments in a function

andre andre at targon.UUCP
Tue May 8 01:32:07 AEST 1990


In article <1990Apr22.010146.5001 at utzoo.uucp> henry at utzoo.uucp (Henry Spencer) writes:
]In article <744 at tmiuv0.uucp> rick at tmiuv0.uucp writes:
]>What's the most portable way for a function to receive an arbitrary list of
]>arguments? ...
]
]The *only* maximally portable way to do this is to use the <stdargs.h>
]facility in ANSI C.  Using <varargs.h>, found in many current systems,
	[ things you should not do ]

There is one more method though,
accept an 'argv' like array as the argument to your function.
as in,

int number_args (a)
char **a;
{
	int n;

	for (n = 0 ; a[n] ; n++)
	    ;

	return n;
}

And if you malloc and realloc the char * array, this size can
change at runtime, while the varargs approach is fixed at compile time.

-- 
The mail|    AAA         DDDD  It's not the kill, but the thrill of the chase.
demon...|   AA AAvv   vvDD  DD        Ketchup is a vegetable.
hits!.@&|  AAAAAAAvv vvDD  DD                    {nixbur|nixtor}!adalen.via
--more--| AAA   AAAvvvDDDDDD    Andre van Dalen, uunet!hp4nl!targon!andre



More information about the Comp.lang.c mailing list