home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / comp / lang / cplus / 18421 < prev    next >
Encoding:
Text File  |  1992-12-25  |  3.4 KB  |  84 lines

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!spool.mu.edu!yale.edu!jvnc.net!newsserver.technet.sg!nuscc!papaya!suresh
  3. From: suresh@papaya.iss.nus.sg (Suresh Thennarangam - Research Scholar)
  4. Subject: Re: Access non-static data members in Motif callback functions.
  5. Message-ID: <1992Dec25.102633.18636@nuscc.nus.sg>
  6. Originator: suresh@papaya
  7. Sender: usenet@nuscc.nus.sg
  8. Organization: Institute of Systems Science, NUS, Singapore
  9. References: <1992Dec21.144344.21100@asl.dl.nec.com> <1992Dec23.232305.5228@microsoft.com>
  10. Date: Fri, 25 Dec 1992 10:26:33 GMT
  11. Lines: 71
  12.  
  13. In article <1992Dec23.232305.5228@microsoft.com> samk@microsoft.com (Sam Kho) writes:
  14. >In article <1992Dec21.144344.21100@asl.dl.nec.com> jng@aslslc71.asl.dl.nec.com (James Ng) writes:
  15. >>
  16. >>We use X11/R4 and Motif 1.1 for our GUI development. Our C++ compiler is
  17. >>Object Center C++ (formerly called Saber C++). When we try to use a
  18. >>non-static member function as a callback, sometimes nonstatic data members
  19. >>get corrupted inside the callback function. Static data members seem to
  20. >>maintain their integrity. Does anyone have similar experience or even
  21. >>solution to solve the above problem? Any suggestion will be appreciated.
  22. >>Suggestion can be mailed to jng@asl.dl.nec.com or posted if you prefer.
  23. >>
  24. >>James Ng
  25. >
  26. >static data members r like global variables.  "this" is irrelevant.  non-
  27. >static data members r like fields in a struct, where "this" is the pointer
  28. >to the struct.  in a non-static member function, "this" is assumed to be
  29. >the first hidden parameter, i.e.:
  30. >
  31. >    class myclass
  32. >    {
  33. >    public:
  34. >        void nonstatic    (int x);
  35. >    };
  36. >
  37. >is like:
  38. >
  39. >    void myclass_nonstatic(myclass *this, int x);
  40. >
  41. >now when Xt calls the callback, the first argument passed is the widget.
  42. >my guess is u'r using the widget as "this"!  i'm surprised u'r even able
  43. >to get non-corrupted values (probably that offset in the widget just happens
  44. >to have the right value).
  45.  
  46. Not very surprising. Quite logical actually. James says above "Static 
  47. data members seem to maintain their integrity". If you combine that with your
  48. statement " static data members r like global variables.  "this" is irrelevant"
  49. and extrapolate, the conclusion one may draw  is that static data members are not
  50. accessed through this. They are allocated storage globally, outside the class
  51. instances. While the actuals are implementation dependant I actually confirmed
  52. this for cfront and g++; sizeof does not reflect the contribution of static
  53. members. 
  54.  
  55. This, then is another implementation-dependant pitfall like virtual functions
  56. (see the thread "Sizeof and Virtual functions). 
  57.  
  58. >
  59. >to verify, cast this into a widget inside the non-static member function,
  60. >and do something with it (e.g. if it's a callback to a PushButton, change
  61. >the label).
  62.  
  63. Yes, that should surely clinch the issue. 
  64.  
  65.  
  66. Regards,
  67.  
  68.  
  69.  
  70.  
  71.       __                  
  72.      (_   / /  o_   o  o |_
  73.      __)/(_( __) (_(_ /_)| )_
  74.  
  75.  
  76. ***************************************************************************
  77. * Suresh Thennarangam               *  EMail: suresh@iss.nus.sg(Internet) *
  78. * Research Scholar                  *         ISSST@NUSVM.BITNET          *
  79. * Institute Of Systems Science      *  Tel:  (065) 772 2588.              *
  80. * National University Of Singapore  *  Facs.: (065) 778 2571          *
  81. * Heng Mui Keng Terrace             *  Telex: ISSNUS RS 39988             *
  82. * Singapore 0511.                   *                                     *
  83. ***************************************************************************
  84.