Re: [Plib-users] legend update
Brought to you by:
sjbaker
|
From: dave <da...@mi...> - 2002-01-29 16:33:50
|
Good tips all, but none of them are the one that instantly popped into
my mind, which is:
If you are going to use the C strings rather than a string class, always
zero the destination space before printing,cat-ing,or copying into it.
For one thing, this forces you to consider the length of the space
before clearing.
<SOAPBOX>
I have found hundreds of bugs in my employers codes over the years
related to sloppy C programming practices, especially strings (and yes,
I too get sloppy). One employer even built a special set of wrappers for
the string functions that eliminated having to think about the n+1 byte
for the terminating zero. It sure looked ugly! :)
Having gotten tired of all this I abandoned C string functions entirely and
learned the iostreams part of C++ and started looking for a String class
in whatever projects I am assigned. If one isnt there I have my own I
wrote. This has saved me so much pain it was well worth it the effort.
But there is a footprint price to be paid if you are in an embedded
environment and using C++. This month's ELJ (Embedded Linux Journal) has
an article on a GUI project for a handheld where they use X-windows but
chose GTK+ instead of FLTK or QT. The complaint was that C++ brings too
many problems and its best to just try to be extremely disciplined in C.
So my usual snappy answer of "just dont use C", ahem, cough cough,
doesnt seem to work anymore, at least for highly tuned environments.
</SOAPBOX>
Regards,
Dave
Oh, BTW, Steve, the translucent widgets are sweet!
Stephen J Baker wrote:
>>void sliderCB( puObject *sli) {
>>
>> float value;
>> char sliText[4];
>>
>> slicb->getValue(&value);
>> sprintf(sliText, "%.2f", value);
>> cout << sliText << endl; // this output is *exactly* what I need
>>
>> slicb->setLegend(sliText); // non-sense chars on the legend :(
>> ...
>>}
>>
>>No matter what I do to try and reformat the string (with sprintf),
>>prior to sending it on the legend, I get on my legend some strange
>>characters. What am I possibly doing wrong?
>>Can somebody see my mistake above?
>>
>
> Someone already (correctly) pointed out that sliText is a local variable
> (which is certainly a problem) - but it's also not large enough.
>
> The '%.2f' format will generate things like '0.01' - four characters
> plus a '\0' byte - making five characters in all. Hence, sliText
> needs to have *AT LEAST* five elements - not four as you declared it.
>
> ----
> Steve Baker (817)619-2657 (Vox/Vox-Mail)
> L3Com/Link Simulation & Training (817)619-2466 (Fax)
> Work: sj...@li... http://www.link.com
> Home: sjb...@ai... http://www.sjbaker.org
>
>
> _______________________________________________
> plib-users mailing list
> pli...@li...
> https://lists.sourceforge.net/lists/listinfo/plib-users
>
>
>
>
|