home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.sys.amiga.programmer
- Path: sparky!uunet!mcsun!sun4nl!wn1.sci.kun.nl!cs.kun.nl!rhialto
- From: rhialto@cs.kun.nl (Olaf Seibert)
- Subject: Re: NULL vs 0 in RKM-Libs
- Message-ID: <1992Jul30.190808.9881@sci.kun.nl>
- Sender: news@sci.kun.nl (NUnet News Owner)
- Organization: University of Nijmegen, The Netherlands
- References: <1992Jul7.153641.27106@sci.kun.nl> <paulk.0nfw@terapin.com> <92192.151112TEW105@psuvm.psu.edu>
- Date: Thu, 30 Jul 1992 19:08:08 GMT
- Lines: 55
-
- In <92192.151112TEW105@psuvm.psu.edu> <TEW105@psuvm.psu.edu> writes:
-
- >>
- >>> 1. In stdio.h: #define NULL __null_pointer_constant
- >>> 2. The compiler recognizes the name __null_pointer_constant
-
- >Uh, what's wrong with #define NULL 0L ?
-
- >I use NULL all the time with my C compiler with no complaints about it
- >no matter what situation its used in.
- >Am I missing something here? (I probably am :)
-
- That the compiler never complains is my problem. I /want/ the compiler
- to complain if someone writes
-
- window->IDCMPFlags = NULL;
- or
- NumberOfFoos = NULL;
- .
- Which I've seen far too much, even in example code from Commodore.
-
- To quote from the C-FAQ file:
-
- 1.8: If "NULL" and "0" are equivalent, which should I use?
-
- A: Many programmers believe that "NULL" should be used in all
- pointer contexts, as a reminder that the value is to be thought
- of as a pointer. Others feel that the confusion surrounding
- "NULL" and "0" is only compounded by hiding "0" behind a
- #definition, and prefer to use unadorned "0" instead. There is
- no one right answer. C programmers must understand that "NULL"
- and "0" are interchangeable and that an uncast "0" is perfectly
- acceptable in initialization, assignment, and comparison
- contexts. Any usage of "NULL" (as opposed to "0") should be
- considered a gentle reminder that a pointer is involved;
- programmers should not depend on it (either for their own
- understanding or the compiler's) for distinguishing pointer 0's
- from integer 0's.
-
- NULL should _not_ be used when another kind of 0 is required,
- even though it might work, because doing so sends the wrong
- stylistic message. (ANSI allows the #definition of NULL to be
- (void *)0, which will not work in non-pointer contexts.) In
- particular, do not use NULL when the ASCII null character (NUL)
- is desired. Provide your own definition
-
- #define NUL '\0'
-
- if you must.
-
- Reference: K&R II Sec. 5.4 p. 102.
-
- --
- ___ Olaf 'Rhialto' Seibert B4f+-t-w--g+k+(+)svmrp+ rhialto@cs.kun.nl
- \X/ It'sneveragoodideatoarriveinthepastwithyourpantsaroundyourknees -Sam
-