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

Johannes Loher johannes.loher at fg4f.de
Wed Jan 16 19:06:18 UTC 2019


On Wednesday, 16 January 2019 at 18:50:51 UTC, 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.

They are, if they are declared immutable (which is no problem if 
using enum would also be ok). The following program outputs "0" 
during compilation:

```
static immutable i = 0;

static if (i == 0)
{
     pragma(msg, i);
}

void main()
{

}
```



More information about the Digitalmars-d mailing list