home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / lang / cplus / 11666 < prev    next >
Encoding:
Text File  |  1992-07-28  |  2.4 KB  |  63 lines

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!taumet!steve
  3. From: steve@taumet.com (Steve Clamage)
  4. Subject: Re: Having this=0, class-name: :main() and tasking in c++
  5. Message-ID: <1992Jul28.161438.2862@taumet.com>
  6. Organization: TauMetric Corporation
  7. References: <1DDA4ACFA5BF800C41@ursula.lucas.lu.se> <23318@alice.att.com> <1992Jul27.155949.6165@sunb10.cs.uiuc.edu>
  8. Distribution: usa
  9. Date: Tue, 28 Jul 1992 16:14:38 GMT
  10. Lines: 51
  11.  
  12. pjl@sparc13.cs.uiuc.edu (Paul Lucas) writes:
  13.  
  14. >In <23318@alice.att.com> ark@alice.att.com (Andrew Koenig) writes:
  15.  
  16. >>In article <1DDA4ACFA5BF800C41@ursula.lucas.lu.se> KOSU_MATSB@ROUTH.KOSUFY.LU.SE writes:
  17.  
  18. >>> Question #1:    Having a 0 "this" pointer. Standard?
  19.  
  20. >>No.  ARM page 176:
  21.  
  22. >>    The effect of calling a nonstatic member function of a class X
  23. >>    for something that is not an object of class X is undefined.
  24.  
  25. >*****>    Oops!  I was in error about my previous post; sorry.  But _why_
  26. >    isn't guaranteed to work for nonstatic, nonvirtual member
  27. >    functions?
  28.  
  29. >        C++            C-code
  30. >        ===            ======
  31. >        ((X*)0)->f();    ==>    f( /* this= */ 0 );
  32.  
  33. Let's call a non-static non-virtual member function an "ordinary member
  34. function".
  35.  
  36. An ordinary member function must be called in conjunction with some
  37. object of appropriate type.  Conceptually, it gets a "this" pointer
  38. to that object.  The language specification does not say how this is
  39. to be implemented.  You show the obvious implementation, but the
  40. obvious implementation is not required.
  41.  
  42. No object will be located at the address represented by literal zero.
  43. Any member function which attempts to manipulate non-static class data,
  44. or which calls functions which do, will fail with a null "this" pointer.
  45.  
  46. An ordinary member function usually operates on class data, or calls
  47. other class functions which do.  It might seem reasonable to say that
  48. an ordinary member function which uses no non-static class data, calls
  49. not functions which do, and calls no virtual functions of the class,
  50. should be guaranteed to work with a null "this" pointer.  (Such a
  51. function would be expected to be static, but let's ignore that.)
  52.  
  53. It might be that the implementation requires more than a simple
  54. passing of the "this" pointer, and the manipulation might fail on a
  55. null pointer.
  56.  
  57. For all these reasons, the language standard cannot guarantee success
  58. for any member function which gets a null "this" pointer.
  59. -- 
  60.  
  61. Steve Clamage, TauMetric Corp, steve@taumet.com
  62. Vice Chair, ANSI C++ Committee, X3J16
  63.