home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: sparky!uunet!stanford.edu!EE.Stanford.EDU!sierra!mcgrant
- From: mcgrant@rascals.stanford.edu (Michael C. Grant)
- Subject: Re: Is (p) instead of (p!=NULL) portable?
- In-Reply-To: robert@alkymi.unit.no's message of Mon, 25 Jan 93 12:56:27 GMT
- Message-ID: <MCGRANT.93Jan25110332@rascals.stanford.edu>
- Sender: usenet@EE.Stanford.EDU (Usenet)
- Organization: Information Systems Laboratory, Stanford University
- References: <1993Jan25.125627.29030@ugle.unit.no>
- Date: 25 Jan 93 11:03:32
- Lines: 21
-
- In article <1993Jan25.125627.29030@ugle.unit.no>
- robert@alkymi.unit.no (Robert Schmidt) writes:
-
- 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?
-
- Yes. By definition, 'if (p)', if p is a pointer, tests to see if p is equal
- to the null pointer, and 'if (!p)' tests to see if it is not.
-
- Also, by definition, 'p = 0' sets p to the null pointer, even if the
- internal representation of the null pointer is not all zeros for some reason.
-
- Mike
-
- --
- "Long hair, short hair--what's the difference once the head's blowed off?" (?)
-