[comp.lang.c] NULL

drw@cullvax.UUCP (03/12/87)

Has anyone considered making NULL a keyword, so we can stop worrying
whether (char *)(1 ? 0 : 0) is a legitimate null pointer?

Dale
-- 
Dale Worley		Cullinet Software
UUCP: ...!seismo!harvard!mit-eddie!cullvax!drw
ARPA: cullvax!drw@eddie.mit.edu
Un*x (a generic name for a class of OS's) != Unix (AT&T's brand of such)

karl@haddock.UUCP (07/15/87)

In article "Re: Writing readable code (what is NULL)" <9695@orchid.UUCP> rbutterworth@orchid.UUCP writes:
>If I were god, when I wrote K&R, I think I'd either build NULL into
>the language, or I would use [ #define NULL(type) ((type)0) ].
>In the former case "p=NULL" would work fine, but "func(NULL)" would
>produce an error since there is no type for it to be coerced to.

There's no need for the error.  If a function prototype covers it, the type is
known; otherwise it can be promoted to (void *) as one of the default argument
promotions%.

>In the latter case, the user would be forced to code "p=NULL(char*);"
>or "func(NULL(int*));".

I think this is too verbose.  Also, it's not that much different from writing
"p=(char *)NULL" or "func((int *)NULL)", which reduces it to case 1.

>Either way there wouldn't be any of this confusion that we have now,
>and will probably always have.

Unless X3J11 has the guts to deprecate "p=0".

In article "A modest proposal" <1362@cullvax.UUCP> drw@cullvax.UUCP (Dale Worley) writes:
|What I propose is the NULL be made into a keyword of the language which acts
|like a constant and whose value is a pointer, and eliminating "0" as the null
|pointer.  As far as I know, no decently written C program will break on this,
|and it would clean a lot of cruft out of the language definition.

In effect, it already is a keyword (in ANSI, anyway).  The trouble is that the
constant 0 is guaranteed to be just as good, and many programs take advantage
of this language quirk.  These programs may not be "decently written" in your
opinion, but until the feature is deprecated it is perfectly valid and is
merely a matter of style.

I support this idea.  However, I suspect there's too much inertia to overcome.

Karl W. Z. Heuer (ima!haddock!karl or karl@haddock.isc.com), The Walking Lint
% There is no such promotion rule at present, but as long as we're rewriting
the language, why not?