home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.std.c++
- Path: sparky!uunet!microsoft!hexnut!jimad
- From: jimad@microsoft.com (Jim Adcock)
- Subject: Re: this == 0 for nonvirtual functions
- Message-ID: <1992Aug20.215455.17279@microsoft.com>
- Date: 20 Aug 92 21:54:55 GMT
- Organization: Microsoft Corporation
- References: <1992Aug18.045605.14220@sunb10.cs.uiuc.edu>
- Keywords: this virtual function undefined
- Lines: 27
-
- In article <1992Aug18.045605.14220@sunb10.cs.uiuc.edu> pjl@sparc10.cs.uiuc.edu (Paul Lucas) writes:
- | To reiterate, all I would like is to guarantee that the *call*
- | to a non-virtual member-function will succeed and that it's my
- | responsibility to check for a non-nil 'this'.
-
- First, note that this would not come at "zero" cost. As in the case of
- assigning to a reference, requiring "this" to be non-null allows compilers
- to avoid generating code to preserve nullness when adjusting pointers
- in the case of MI. In the case of references, this issue has already
- been reviewed and decided upon: one is not allowed to have null references.
-
- Further, note that member functions can be called either on a pointer or
- on a reference. If the language were to PERMIT calling member functions
- on a null pointer, such would not ALLOW *you* to test for null "this" inside
- you member functions, but rather would REQUIRE all of *us* to test for
- null "this" inside ALL *our* non-virtual member functions -- because a user
- of our class such as yourself could then legally call *our* member functions via
- a null pointer. If such were the case then, the only sane remedy C++
- programmers would have would be to declare all their member functions virtual.
- Then *you* *still* could not legally call these members on a null pointer --
- but many member functions would now be needlessly slow and generate needlessly
- large code.
-
- I suggess instead that you use friend functions or static member functions
- where you feel you must address null pointers implicitly. Alternately, note
- that the users of your class may be the ones in the best position to perform
- the null pointer tests [explicitly].
-