home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / std / cplus / 1092 < prev    next >
Encoding:
Text File  |  1992-08-18  |  1.5 KB  |  43 lines

  1. Newsgroups: comp.std.c++
  2. Path: sparky!uunet!uunet.ca!frumious!pat
  3. From: pat@frumious.uucp (Patrick Smith)
  4. Subject: Re: this == 0 for nonvirtual functions
  5. Message-ID: <1992Aug19.042214.1189@frumious.uucp>
  6. Date: Wed, 19 Aug 1992 04:22:14 GMT
  7. Reply-To: uunet.ca!frumious!pat
  8. References: <1992Aug18.045605.14220@sunb10.cs.uiuc.edu>
  9. Organization: None
  10. Lines: 31
  11.  
  12. pjl@sparc10.cs.uiuc.edu (Paul Lucas) writes:
  13. |    IMHO, the ability to *depend upon* the (desired) fact that
  14. |    *calling* a non-virtual member-function with a nil pointer is
  15. |    *guaranteed* to be harmless seems worthwhile (and its addition
  16. |    to the language wouldn't break anything as far as I can tell).
  17.  
  18. If this change to the language were made, it might be appropriate
  19. not to include the case of calling a member function with a nil
  20. pointer to a class virtually derived from the class where the
  21. function is defined:
  22.  
  23.    class Base { void f(); };
  24.    class Derived : public virtual Base {};
  25.    ...
  26.    Derived* p;
  27.    p->f();
  28.  
  29. If I understand correctly, in most implementations the conversion
  30. of p to a Base* will require examining the contents of *p.
  31. If p may be 0, then the compiler must insert extra code to
  32. treat this case correctly.
  33.  
  34. Of course, this extra code is currently necessary for all conversions
  35. of a Derived* to a Base* where the compiler can't be sure that
  36. the pointer is non-nil.  So perhaps the extra overhead for the
  37. function calls wouldn't be seen as significant.
  38.  
  39. -- 
  40. Patrick Smith
  41. uunet.ca!frumious!pat
  42. pat%frumious.uucp@uunet.ca
  43.