Domingo Alvarez Duarte wrote:
> Greg Ercolano wrote:
>> Z:\tmp>.\foo.exe
>> 00408040 = 00408048 = 00408050
>> ^^ ^^ ^^
> I didn't tried it but anyway the sizeof() will be replaced at compile
> time by it's size and no double constant string will appear.
Hmm, good point.
Indeed this seems to be the case in both VC and g++; this test:
#include <stdio.h>
int main() {
printf("%d = %d = %d\n", sizeof("unique"), sizeof("unique"),
sizeof("unique"));
return 0;
}
What's interesting here is the string "unique" does not end up
in the binary with either compiler.
Not looking at the C/C++ spec, I suppose a smart compiler should
not bother to allocate the string at all if it appears inside of
sizeof().
So assuming this is defined behavior of C/C++ compilers,
I'd be +1 on your macro technique, since it prevents programmer errors.
The main concern is embedded compilers that fltk supports; they
tend to be both tight on memory but borderline on compiler features.
But if the sizeof() behavior regarding read-only strings is actually
in the spec (and not a compiler specific optimization), then we could
at least say "it's a bug in the compiler" if an embedded designer
were to notice an overuse of memory.
_______________________________________________
fltk-dev mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk-dev