home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: sparky!uunet!munnari.oz.au!cs.mu.OZ.AU!munta.cs.mu.OZ.AU!fjh
- From: fjh@munta.cs.mu.OZ.AU (Fergus James HENDERSON)
- Subject: Re: testing for null pointer
- Message-ID: <9236421.23910@mulga.cs.mu.OZ.AU>
- Sender: news@cs.mu.OZ.AU
- Organization: Computer Science, University of Melbourne, Australia
- References: <1992Dec28.181916.7484@litwin.com>
- Date: Tue, 29 Dec 1992 10:40:08 GMT
- Lines: 29
-
- mbb@litwin.com (Mark Beyleveld) writes:
-
- >Assuming I declare
- >
- >int* aPointer = 0;
- >
- >is it valid to write
- >
- >if (aPointer) {...}
-
- Yes.
-
- >Also, are the rules for pointers to member functions the same?
-
- Yes. [See the reference manual sections 6.4.1 ('if' statements),
- 4.6 (null pointers), and 4.8 (null pointers to members)].
- Actually 6.4.1 is perhaps a little vague. It says
- "The expression [in an 'if' statement] is evaluated and if it is
- nonzero ..."
- Presumably what it means for a pointer to member to be "nonzero" is for it to
- be different to the pointer which results when a constant expression that
- evaluates to zero is converted to a pointer to member (i.e. different from
- a null pointer to member).
-
- --
- Fergus Henderson fjh@munta.cs.mu.OZ.AU
- This .signature virus is a self-referential statement that is true - but
- you will only be able to consistently believe it if you copy it to your own
- .signature file!
-