string literals

Jack Applegame japplegame at gmail.com
Fri May 31 07:20:44 PDT 2013


What's the reason that the string literal is a dynamic array, not 
a static?
So sometimes it is not possible to get string length compile time:

void foo(T: E[N], E, size_t N)(auto ref T data) {
     pragma(msg, "static");
     pragma(msg, data.length);
}
void foo(T: E[], E)(auto ref T data) {
     pragma(msg, "dynamic");
     pragma(msg, data.length);
     // Error: variable data
     // cannot be read at compile time
}
...
foo("test");



More information about the Digitalmars-d-learn mailing list