Dude! Where's my string constant?
kris
foo at bar.com
Tue Jan 23 12:09:05 PST 2007
Does D have a compile-time string constants? One that doesn't wind up in
the obj file when it is unused?
const char[] Foo = "foo";
Apparently resides in the object file, used or not. Just like const int
does. For true compile-time integer constants, we're supposed to use
enum -- but what of strings? Enum currently doesn't like char[] :)
Suggestions for faking it include:
* char[] Foo() { return "foo"; }
* template Foo { const Foo="foo"; }
The former *should* get removed by the linker as unused, while the
latter apparently gets eliminated by way of lack-of-expansion.
However, going to these lengths is surely counter-intuitive?
More information about the Digitalmars-d
mailing list