[ Usenet FAQs | Search | Web FAQs | Documents | RFC Index ]
    Search the FAQ Archives

Part1 - Part2 - Part3 - Part4 - Part5 - Part6 - Part7 - Single Page

Top Document: comp.windows.x Frequently Asked Questions (FAQ) 6/7
Previous Document: 140)+ How do I check whether an Xt widget is still valid?
Next Document: 148) Why isn't there an XtReparentWidget call like XReparentWindow?


147) Why can't I get data back in my callback procedure?



You may hit a situation in which using XtAddCallback(button, XtNcallback,
CBproc, pointer) doesn't work to retrieve "pointer".

Almost certainly, what you are seeing is the effect of using local variables
after they are no longer in existence. In the above line of code, "pointer"
is probably a local variable declared within the block of code making the call
to XtAddCallback; it is valid only within the scope of the callback, and is
not valid by the time the callback CBproc gets called. Within CBproc, the
client_data argument is pointing to somewhere on the stack -- whereever
pointer was when it was used.  

Short of using global or static data, the best solution is to allocate a
pointer to the data you need and free it in the callback routine.

Short values such as integers can be passed directly without resorting to
this code; nor do you need to do allocations for other data which will be in
existence when the callback is called, such as other widgets which haven't
been destroyed.



Top Document: comp.windows.x Frequently Asked Questions (FAQ) 6/7
Previous Document: 140)+ How do I check whether an Xt widget is still valid?
Next Document: 148) Why isn't there an XtReparentWidget call like XReparentWindow?

Part1 - Part2 - Part3 - Part4 - Part5 - Part6 - Part7 - Single Page


[ Usenet FAQs | Search | Web FAQs | Documents | RFC Index ]

Send corrections/additions to the FAQ Maintainer:
faq%craft@uunet.uu.net (X FAQ maintenance address)

Last Update July 06 2009 @ 00:07 AM

© 2008 FAQS.ORG. All rights reserved.