home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / lang / cplus / 19976 < prev    next >
Encoding:
Text File  |  1993-01-28  |  1.3 KB  |  39 lines

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!taumet!steve
  3. From: steve@taumet.com (Steve Clamage)
  4. Subject: Re: Is (p) instead of (p!=NULL) portable? 
  5. Message-ID: <1993Jan26.191831.23263@taumet.com>
  6. Organization: TauMetric Corporation
  7. References: <1993Jan25.125627.29030@ugle.unit.no> <1993Jan26.091708.11214@cbfsb.cb.att.com>
  8. Date: Tue, 26 Jan 1993 19:18:31 GMT
  9. Lines: 28
  10.  
  11. nh@cbnewsg.cb.att.com (nicholas.hounsome) writes:
  12.  
  13. >> ... the constructs 
  14. >>       if (p)
  15. >> and
  16. >>       if (!p)
  17. >> checks for NULL and non-NULL respectively.  Is this portable to *all*
  18. >> platforms?
  19.  
  20. >It is NOT portable for C.
  21. >It is portable for C++ which is the group that you have posted to -
  22. >did you mean to?
  23.  
  24. Just to reduce confusion, Hounsome's comments are not correct.
  25. Tony Hansen posted the best answer to this question.
  26.  
  27. Both C and C++ guarantee that any pointer which compares equal to a
  28. null pointer constant is a null pointer, and any null pointer compares
  29. equal to a null pointer constant.  Finally, any null pointer compares
  30. equal to any other null pointer when suitably cast.
  31.  
  32. In C++, a literal zero is most appropriate for use as a null pointer
  33. constant.  In any event, for both C and C++, use the NULL macro which is
  34. supplied in the standard header files in preference to writing your own
  35. macro.
  36. -- 
  37.  
  38. Steve Clamage, TauMetric Corp, steve@taumet.com
  39.