Re: [Plib-users] Problem with setLabel, weirdness ensues.
Brought to you by:
sjbaker
From: Jan R. <slo...@gm...> - 2008-06-11 20:20:39
|
Am Wed, 11 Jun 2008 15:55:57 -0400 schrieb "cory barton" <co...@gm...>: > void init_pui_widgets( void ) { > //unused variable bbb > char bbb[ PUSTRING_MAX ]; //if I remove this setLabel() fails! > char txt[ PUSTRING_MAX ]; > puInit(); Hi, this won't work, because txt is only allocated on the stack (local variable), and it will be destroyed at the end of the function. Introducing bbb cures the problem because it pushes txt further down on the stack, thus avoiding that it is overwritten by the rest of your code. If you introduce another function that uses more stack space, chances are that the above code won't work anymore. puObject::setLabel() does not copy the string; it just copies the pointer to the string. Therefore you have to provide a buffer that doesn't go out of scope as long as your widget exists. Kind regards, Jan R. -- Jan Reucker email: jan dot reucker at web dot de web: http://www.reucker-online.de |