Use of NULL as a pointer in C

mouse at mcgill-vision.UUCP mouse at mcgill-vision.UUCP
Sun Nov 23 08:47:27 AEST 1986


In article <250 at rabbit1.UUCP>, barber at rabbit1.UUCP (Steve Barber) writes:
> The use of the identifier NULL, as defined by stdio.h in all UNIXes
> I've ever seen [...], by itself as any kind of pointer, is a
> non-portable usage and as such is incorrect [...]

Nearly.  It *is* portable to write (assuming NULL is 0, as it is on our
system)
	ptr_var = NULL;
or
	if (ptr_expr == NULL)
(or !=).  It is *not* portable to write
	setbuf(stdout,NULL); /* should be (char *)NULL */
(even aside from the issue of setbuf()'s portability).

> When writing code, bite the bullet and type those extra 8 or so
> characters [...]: (char *) NULL, (int *) NULL, or [whatever].

I prefer to simply never use NULL.  I write my code with zeros.  This
way I don't get bitten when porting to a system where some well-meaning
clod with the famous "little learning" decided to "avoid" the "problem"
and make NULL ((char *)0).

					der Mouse

USA: {ihnp4,decvax,akgua,utzoo,etc}!utcsri!mcgill-vision!mouse
     think!mosart!mcgill-vision!mouse
Europe: mcvax!decvax!utcsri!mcgill-vision!mouse
ARPAnet: think!mosart!mcgill-vision!mouse at harvard.harvard.edu

[USA NSA food: terrorist, cryptography, DES, drugs, CIA, secret, decode]



More information about the Comp.lang.c mailing list