why global immutable string variable cannot be used after "case"?

Cheng Wei rivercheng at gmail.com
Fri Sep 23 01:30:10 PDT 2011


import std.stdio;
immutable HELLO = "hello";

void main() {
     auto string = "hello";
     switch(string) {
          case HELLO:
              writeln("hello");
              break;
          default:
              writeln("unknown");
              break;
     }
}

testCase.d(7): Error: case must be a string or an integral constant,
not HELLO

If immutable cannot be used, what else can be used to replace #define
in C?

Thanks a lot.


More information about the Digitalmars-d-learn mailing list