stdarg

Stanley Friesen sarima at tdatirv.UUCP
Fri Feb 8 05:31:45 AEST 1991


In article <1991Feb7.043715.1224 at Think.COM> barmar at think.com (Barry Margolin) writes:
 
>Well, consider a function taking a variable number of strings, followed by
>a null pointer.  The type is known by definition, and the number of
>arguments can be determined by looking at them.
>
>  While this style could
>easily be replaced with one where there is an initial fixed argument
>containing the count of variable arguments, that's more prone to error:

Ah, but the style you specified above *does* have one 'fixed' argument,
since all valid calls must pass *at* *least* one argument, a null pointer.
(That is an attempt to call it with *no* arguments is a serious error).
Furthermore this single required argument is of type (char *), even if it
is the null pointer.  Thus the specification:
	void sfunc(char *, ...);
is a perfectly valid way of prototyping it.

Thus the style you mentioned is in fact compatible with stdarg.h, and is best
treated as requiring one character pointer argument.  A varargs.h approach
which pretends that there are no required arguments is actually misleading.
-- 
---------------
uunet!tdatirv!sarima				(Stanley Friesen)



More information about the Comp.lang.c mailing list