Header problems

Doug Gwyn gwyn at brl-smoke.ARPA
Thu Mar 10 05:09:24 AEST 1988


In article <3351 at chinet.UUCP> dag at chinet.UUCP (Daniel A. Glasser) writes:
>In article <7412 at brl-smoke.ARPA> gwyn at brl.arpa (Doug Gwyn (VLD/VMB) <gwyn>) writes:
>>	#define NULL 0
>Your use of NULL === 0 promotes unportable code, and is considered to be
>bad programming style in a world where portability across multiple machine
>architectures (ie, PDP-11, VAX-11, M680x0, I80x86 and Z800x) is required
>for commercial reasons.
>	#define	NULL	((void *)0)

My original advice was precisely correct.  Yours perpetuates the myth
that all pointers have the same representation.  Since this is not so
in general, there is no alternative for the portable C programmer but
to explicitly cast 0 or NULL to the proper type when it is used as a
function parameter.

For ANSI C, your suggestion is as good as mine (but no better); in
non-ANSI C, there is no (void *).  ANSI C has the additional advantage
that either form of NULL used as a function parameter will be
automatically converted to the right type, if a non-variadic function
prototype is in scope.

It seems that we have to go through this discussion every six months.



More information about the Comp.lang.c mailing list