home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / sys / amiga / programm / 11841 < prev    next >
Encoding:
Text File  |  1992-07-30  |  2.5 KB  |  67 lines

  1. Newsgroups: comp.sys.amiga.programmer
  2. Path: sparky!uunet!mcsun!sun4nl!wn1.sci.kun.nl!cs.kun.nl!rhialto
  3. From: rhialto@cs.kun.nl (Olaf Seibert)
  4. Subject: Re: NULL vs 0 in RKM-Libs
  5. Message-ID: <1992Jul30.190808.9881@sci.kun.nl>
  6. Sender: news@sci.kun.nl (NUnet News Owner)
  7. Organization: University of Nijmegen, The Netherlands
  8. References: <1992Jul7.153641.27106@sci.kun.nl> <paulk.0nfw@terapin.com> <92192.151112TEW105@psuvm.psu.edu>
  9. Date: Thu, 30 Jul 1992 19:08:08 GMT
  10. Lines: 55
  11.  
  12. In <92192.151112TEW105@psuvm.psu.edu> <TEW105@psuvm.psu.edu> writes:
  13.  
  14. >>
  15. >>> 1. In stdio.h: #define NULL __null_pointer_constant
  16. >>> 2. The compiler recognizes the name __null_pointer_constant
  17.  
  18. >Uh, what's wrong with #define NULL 0L ?
  19.  
  20. >I use NULL all the time with my C compiler with no complaints about it
  21. >no matter what situation its used in.
  22. >Am I missing something here?  (I probably am :)
  23.  
  24. That the compiler never complains is my problem. I /want/ the compiler
  25. to complain if someone writes
  26.  
  27.     window->IDCMPFlags = NULL;
  28. or
  29.     NumberOfFoos = NULL;
  30. .
  31. Which I've seen far too much, even in example code from Commodore.
  32.  
  33. To quote from the C-FAQ file:
  34.  
  35. 1.8:    If "NULL" and "0" are equivalent, which should I use?
  36.  
  37. A:    Many programmers believe that "NULL" should be used in all
  38.     pointer contexts, as a reminder that the value is to be thought
  39.     of as a pointer.  Others feel that the confusion surrounding
  40.     "NULL" and "0" is only compounded by hiding "0" behind a
  41.     #definition, and prefer to use unadorned "0" instead.  There is
  42.     no one right answer.  C programmers must understand that "NULL"
  43.     and "0" are interchangeable and that an uncast "0" is perfectly
  44.     acceptable in initialization, assignment, and comparison
  45.     contexts.  Any usage of "NULL" (as opposed to "0") should be
  46.     considered a gentle reminder that a pointer is involved;
  47.     programmers should not depend on it (either for their own
  48.     understanding or the compiler's) for distinguishing pointer 0's
  49.     from integer 0's.
  50.  
  51.     NULL should _not_ be used when another kind of 0 is required,
  52.     even though it might work, because doing so sends the wrong
  53.     stylistic message.  (ANSI allows the #definition of NULL to be
  54.     (void *)0, which will not work in non-pointer contexts.)  In
  55.     particular, do not use NULL when the ASCII null character (NUL)
  56.     is desired.  Provide your own definition
  57.  
  58.         #define NUL '\0'
  59.  
  60.     if you must.
  61.  
  62.     Reference: K&R II Sec. 5.4 p. 102.
  63.  
  64. -- 
  65. ___ Olaf 'Rhialto' Seibert      B4f+-t-w--g+k+(+)svmrp+  rhialto@cs.kun.nl
  66. \X/   It'sneveragoodideatoarriveinthepastwithyourpantsaroundyourknees -Sam
  67.