Marc R.J. Brevoort wrote:
> On Sat, 29 Sep 2007, Greg Ercolano wrote:
>
>>> If I try to set a label like so, the label contents look garbled:
>>> this->tracknum->label(labeltext);
>
>> Sounds like your char array is going out of scope
>> Either make sure your char declaration doesn't go out of scope,
>> or try instead:
>> this->tracknum->copy_label(labeltext);
>
> Ah, I had mistakenly assumed that ->label would already make a copy for
> exactly that reason. I wasn't aware that a copy_label method existed, glad
> it was something trivial.
Ya, I'd always wondered about why fltk didn't make copies always,
but realized it's often the case the label is a static string in the
app,
so it's a big waste to have fltk /always/ make dynamic copies of
everything.
It's interesting the language doesn't provide a way to detect at runtime
whether a pointer references a static const (read only) or dynamic
memory.
Then fltk could have one label() function, eg:
SomeWidget::label(const char *val) {
if ( ! is_static_const(_label) ) { free(_label); }
if ( ! is_static_const(val) ) { _label = strdup(val); }
else { _label = val; }
}
..which could avoid common stumbling blocks for API use, and prevent
memory misuse.
_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk