Variadic functions

Chip Salzenberg chip at ateng.ateng.com
Sun Nov 13 07:50:26 AEST 1988


    WARNING -- NULL ALERT.
    If you understand NULL pointers, skip this article.

According to crossgl at ingr.UUCP (Gordon Cross):
>   Wouldn't it be much nicer to be able to call the
>   function with the single line
>
>        yourfunction ("arg1", "arg2", ... , 0);

Correct ways to code this function call would be:

	yourfunction ("arg1", "arg2", ... , (char *) 0);
or
	yourfunction ("arg1", "arg2", ... , (char *) NULL);

The reason?  Neither uncasted 0 nor uncasted NULL [1] is acceptable as an
actual function parameter of any pointer type.  (Except in the presence
of a function prototype, of course; but this is a variadic function
we're discussing, so prototypes are almost irrelevant.)

[1]   According to K&R and the dpANS, "#define NULL 0" is permitted.
-- 
Chip Salzenberg             <chip at ateng.com> or <uunet!ateng!chip>
A T Engineering             Me?  Speak for my company?  Surely you jest!
	   Beware of programmers carrying screwdrivers.



More information about the Comp.lang.c mailing list