home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.std.c++
- Path: sparky!uunet!uunet.ca!frumious!pat
- From: pat@frumious.uucp (Patrick Smith)
- Subject: Re: this == 0 for nonvirtual functions
- Message-ID: <1992Aug19.042214.1189@frumious.uucp>
- Date: Wed, 19 Aug 1992 04:22:14 GMT
- Reply-To: uunet.ca!frumious!pat
- References: <1992Aug18.045605.14220@sunb10.cs.uiuc.edu>
- Organization: None
- Lines: 31
-
- pjl@sparc10.cs.uiuc.edu (Paul Lucas) writes:
- | IMHO, the ability to *depend upon* the (desired) fact that
- | *calling* a non-virtual member-function with a nil pointer is
- | *guaranteed* to be harmless seems worthwhile (and its addition
- | to the language wouldn't break anything as far as I can tell).
-
- If this change to the language were made, it might be appropriate
- not to include the case of calling a member function with a nil
- pointer to a class virtually derived from the class where the
- function is defined:
-
- class Base { void f(); };
- class Derived : public virtual Base {};
- ...
- Derived* p;
- p->f();
-
- If I understand correctly, in most implementations the conversion
- of p to a Base* will require examining the contents of *p.
- If p may be 0, then the compiler must insert extra code to
- treat this case correctly.
-
- Of course, this extra code is currently necessary for all conversions
- of a Derived* to a Base* where the compiler can't be sure that
- the pointer is non-nil. So perhaps the extra overhead for the
- function calls wouldn't be seen as significant.
-
- --
- Patrick Smith
- uunet.ca!frumious!pat
- pat%frumious.uucp@uunet.ca
-