runtime 'sizeof()'?

Guy Harris guy at rlgvax.UUCP
Mon Feb 11 15:47:22 AEST 1985


> #define Null(type) ((type *) 0)
> 
> ...
> 	if ((fp = fopen(filename, "r")) == Null(FILE))
> 	    ...
> 
> You get the idea.  Easy to use and it makes the point (pun not intended)
> evident.

Although it isn't necessary; the compiler knows that the LHS of the "==" is a
"FILE *" so it can coerce the "0" to a null FILE *.  In ANSI Standard C
it can even be told that the Nth argument to a function is a FILE * and
will coerce 0 there; the only place this doesn't work is in functions
which take a variable number of arguments.  The main "offender" here is
"execl", which is just a bit of syntactic sugar - anything you can do with
"execl" you can do with "execv" at the expense of having to build an
argument vector somewhere else.

	Guy Harris
	{seismo,ihnp4,allegra}!rlgvax!guy



More information about the Comp.lang.c mailing list