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

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!zaphod.mps.ohio-state.edu!pacific.mps.ohio-state.edu!linac!att!cbnewsk!pegasus!hansen
  3. From: hansen@pegasus.att.com (Tony L. Hansen)
  4. Subject: Re: Is (p) instead of (p!=NULL) portable? 
  5. Organization: AT&T
  6. Date: Tue, 26 Jan 1993 02:21:27 GMT
  7. Message-ID: <1993Jan26.022127.29217@cbnewsk.cb.att.com>
  8. Summary: yes
  9. Keywords: null pointers, C, C++
  10. References: <1993Jan25.125627.29030@ugle.unit.no>
  11. Sender: hansen@cbnewsk.cb.att.com (tony.l.hansen)
  12. Lines: 27
  13.  
  14. < From: robert@alkymi.unit.no (Robert Schmidt)
  15. < In PC C's, the NULL pointer is defined with a bit pattern of all zero's,
  16. < and the constructs
  17. <      if (p)
  18. <and
  19. <      if (!p)
  20. < checks for NULL and non-NULL respectively.  Is this portable to *all*
  21. < platforms?
  22.  
  23. The bit pattern used for null pointers is irrelevant to the question. By
  24. definition,
  25.  
  26.     if (p)
  27.  
  28. is exactly equivalent to
  29.  
  30.     if (p != 0)
  31.  
  32. For all pointer comparisons against 0, the constant 0 is converted by the
  33. compiler to the appropriate bit pattern for the null pointer for that
  34. machine, and then the comparison is done.
  35.  
  36. So, the answer to your question is "yes, it is portable to all platforms".
  37.  
  38.                     Tony Hansen
  39.                 hansen@pegasus.att.com, tony@attmail.com
  40.                 att!pegasus!hansen, attmail!tony
  41.