home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: sparky!uunet!zaphod.mps.ohio-state.edu!pacific.mps.ohio-state.edu!linac!att!cbnewsk!pegasus!hansen
- From: hansen@pegasus.att.com (Tony L. Hansen)
- Subject: Re: Is (p) instead of (p!=NULL) portable?
- Organization: AT&T
- Date: Tue, 26 Jan 1993 02:21:27 GMT
- Message-ID: <1993Jan26.022127.29217@cbnewsk.cb.att.com>
- Summary: yes
- Keywords: null pointers, C, C++
- References: <1993Jan25.125627.29030@ugle.unit.no>
- Sender: hansen@cbnewsk.cb.att.com (tony.l.hansen)
- Lines: 27
-
- < From: robert@alkymi.unit.no (Robert Schmidt)
- < In PC C's, the NULL pointer is defined with a bit pattern of all zero's,
- < and the constructs
- < if (p)
- <and
- < if (!p)
- < checks for NULL and non-NULL respectively. Is this portable to *all*
- < platforms?
-
- The bit pattern used for null pointers is irrelevant to the question. By
- definition,
-
- if (p)
-
- is exactly equivalent to
-
- if (p != 0)
-
- For all pointer comparisons against 0, the constant 0 is converted by the
- compiler to the appropriate bit pattern for the null pointer for that
- machine, and then the comparison is done.
-
- So, the answer to your question is "yes, it is portable to all platforms".
-
- Tony Hansen
- hansen@pegasus.att.com, tony@attmail.com
- att!pegasus!hansen, attmail!tony
-