enum str = "abc"; vs string str = "abc";

Steven Schveighoffer schveiguy at gmail.com
Wed Jan 16 19:10:02 UTC 2019


On 1/16/19 1:50 PM, H. S. Teoh wrote:
> Also, you may have no choice but to use an enum if
> `str` is referenced by compile-time code, since static globals would not
> be readable at compile-time.

Not sure what you mean, this should work.

Only immutable globals that aren't initialized until runtime can't be used.

e.g.:

immutable string s;
immutable string s2 = "abc";

shared static this()
{
    s = "abc";
}

pragma(msg, s); // error
pragma(msg, s2); // OK


-Steve


More information about the Digitalmars-d mailing list