Should all enums be immutable?

Stewart Gordon smjg_1998 at yahoo.com
Sat Apr 9 17:31:58 PDT 2011


On 09/04/2011 22:58, Jonathan M Davis wrote:
<snip>
>> So how, exactly, does the runtime get at data that doesn't exist?
>
> Every time that you use an enum, it's replaced with the enum's value. So, it's
> like you put a literal there which was identtical to the enum's value. So,
<snip>

That's what I'd made out people were saying.  But Don seemed to be claiming that the [1, 
2, 3, 4] doesn't exist at runtime.

> If a had been an immutable variable, then a would not have been replaced with
> its value in the writeln call, but rather a would be passed to writeln.

Exactly.

What I'm claiming ought to happen is for a to be replaced at compiletime with the (length, 
address) tuple pointing to [1, 2, 3, 4].  Am I imagining it, or is this basically the way 
string literals work?

Stewart.


More information about the Digitalmars-d mailing list