Path: utzoo!attcan!uunet!lll-winken!lll-lcc!ames!nrl-cmf!cmcl2!brl-adm!brl-smoke!gwyn From: gwyn@brl-smoke.ARPA (Doug Gwyn ) Newsgroups: comp.lang.c Subject: Re: NULL etc. Message-ID: <8191@brl-smoke.ARPA> Date: 30 Jun 88 16:39:26 GMT References:<6966@cup.portal.com> Reply-To: gwyn@brl.arpa (Doug Gwyn (VLD/VMB) ) Organization: Ballistic Research Lab (BRL), APG, MD. Lines: 24 In article <6966@cup.portal.com> Paul_L_Schauble@cup.portal.com writes: > is #define NULL (char *)0 really portable?? No. It never has been, and in Standard C it will cause diagnostics. >This becomes a very interesting question since I have seen postings that >state that the value on NULL for ANSI C is (void *)0. Seems to me that this >has all of the same problems. Is this really what the standard says? If so, >where have I gone wrong above? Where you have gone wrong is in not reading carefully (or not being sufficiently particular about whom you believe). Standard-conforming implementations shall define NULL (in the headers where it is defined) as either 0 or ((void *)0), implementor's choice. The latter definition can be used to catch more programming errors (for example, using NULL as a case in a switch or as an array index). void *s have special properties (not surprising, since there are no void objects). The relevant property here is that any valid pointer may be converted to void * and back without loss of significant information. This, combined with the requirement that null pointers of all types compare equal, implies that ((void *)0) is just as good as 0 for use as a "generic" null pointer. ("Generic" is in quotes because NULL isn't really generic, it just acts that way in most contexts.)