home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: sparky!uunet!taumet!steve
- From: steve@taumet.com (Steve Clamage)
- Subject: Re: Is (p) instead of (p!=NULL) portable?
- Message-ID: <1993Jan26.191831.23263@taumet.com>
- Organization: TauMetric Corporation
- References: <1993Jan25.125627.29030@ugle.unit.no> <1993Jan26.091708.11214@cbfsb.cb.att.com>
- Date: Tue, 26 Jan 1993 19:18:31 GMT
- Lines: 28
-
- nh@cbnewsg.cb.att.com (nicholas.hounsome) writes:
-
- >> ... the constructs
- >> if (p)
- >> and
- >> if (!p)
- >> checks for NULL and non-NULL respectively. Is this portable to *all*
- >> platforms?
-
- >It is NOT portable for C.
- >It is portable for C++ which is the group that you have posted to -
- >did you mean to?
-
- Just to reduce confusion, Hounsome's comments are not correct.
- Tony Hansen posted the best answer to this question.
-
- Both C and C++ guarantee that any pointer which compares equal to a
- null pointer constant is a null pointer, and any null pointer compares
- equal to a null pointer constant. Finally, any null pointer compares
- equal to any other null pointer when suitably cast.
-
- In C++, a literal zero is most appropriate for use as a null pointer
- constant. In any event, for both C and C++, use the NULL macro which is
- supplied in the standard header files in preference to writing your own
- macro.
- --
-
- Steve Clamage, TauMetric Corp, steve@taumet.com
-