home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: sparky!uunet!spool.mu.edu!yale.edu!jvnc.net!newsserver.technet.sg!nuscc!papaya!suresh
- From: suresh@papaya.iss.nus.sg (Suresh Thennarangam - Research Scholar)
- Subject: Re: Access non-static data members in Motif callback functions.
- Message-ID: <1992Dec25.102633.18636@nuscc.nus.sg>
- Originator: suresh@papaya
- Sender: usenet@nuscc.nus.sg
- Organization: Institute of Systems Science, NUS, Singapore
- References: <1992Dec21.144344.21100@asl.dl.nec.com> <1992Dec23.232305.5228@microsoft.com>
- Date: Fri, 25 Dec 1992 10:26:33 GMT
- Lines: 71
-
- In article <1992Dec23.232305.5228@microsoft.com> samk@microsoft.com (Sam Kho) writes:
- >In article <1992Dec21.144344.21100@asl.dl.nec.com> jng@aslslc71.asl.dl.nec.com (James Ng) writes:
- >>
- >>We use X11/R4 and Motif 1.1 for our GUI development. Our C++ compiler is
- >>Object Center C++ (formerly called Saber C++). When we try to use a
- >>non-static member function as a callback, sometimes nonstatic data members
- >>get corrupted inside the callback function. Static data members seem to
- >>maintain their integrity. Does anyone have similar experience or even
- >>solution to solve the above problem? Any suggestion will be appreciated.
- >>Suggestion can be mailed to jng@asl.dl.nec.com or posted if you prefer.
- >>
- >>James Ng
- >
- >static data members r like global variables. "this" is irrelevant. non-
- >static data members r like fields in a struct, where "this" is the pointer
- >to the struct. in a non-static member function, "this" is assumed to be
- >the first hidden parameter, i.e.:
- >
- > class myclass
- > {
- > public:
- > void nonstatic (int x);
- > };
- >
- >is like:
- >
- > void myclass_nonstatic(myclass *this, int x);
- >
- >now when Xt calls the callback, the first argument passed is the widget.
- >my guess is u'r using the widget as "this"! i'm surprised u'r even able
- >to get non-corrupted values (probably that offset in the widget just happens
- >to have the right value).
-
- Not very surprising. Quite logical actually. James says above "Static
- data members seem to maintain their integrity". If you combine that with your
- statement " static data members r like global variables. "this" is irrelevant"
- and extrapolate, the conclusion one may draw is that static data members are not
- accessed through this. They are allocated storage globally, outside the class
- instances. While the actuals are implementation dependant I actually confirmed
- this for cfront and g++; sizeof does not reflect the contribution of static
- members.
-
- This, then is another implementation-dependant pitfall like virtual functions
- (see the thread "Sizeof and Virtual functions).
-
- >
- >to verify, cast this into a widget inside the non-static member function,
- >and do something with it (e.g. if it's a callback to a PushButton, change
- >the label).
-
- Yes, that should surely clinch the issue.
-
-
- Regards,
-
-
-
-
- __
- (_ / / o_ o o |_
- __)/(_( __) (_(_ /_)| )_
-
-
- ***************************************************************************
- * Suresh Thennarangam * EMail: suresh@iss.nus.sg(Internet) *
- * Research Scholar * ISSST@NUSVM.BITNET *
- * Institute Of Systems Science * Tel: (065) 772 2588. *
- * National University Of Singapore * Facs.: (065) 778 2571 *
- * Heng Mui Keng Terrace * Telex: ISSNUS RS 39988 *
- * Singapore 0511. * *
- ***************************************************************************
-