Should all enums be immutable?
Don
nospam at nospam.com
Wed Apr 6 08:24:32 PDT 2011
Stewart Gordon wrote:
> On 04/04/2011 10:32, Don wrote:
> <snip>
>> Yes. The ONLY reason those manifest constants exist at all, is so that
>> they don't exist at
>> run time. They have no address. Any case where taking a reference to
>> them works, is a
>> compiler bug.
> <snip>
>
> Eh what? In the case of simple value-type constants, this makes sense.
> But when they're reference types, many copies exist at run time, rather
> than only one. This is certainly not an advantage on any level.
No. NONE exist at run time. That is the whole point. No enum should ever
exist in the compiler. That's the only difference between immutable and
enum.
> A reasonable way of doing it is such that every instance of the same
> enum value has the same bit pattern. For pure value types (primitive
> types, static arrays and structs/unions consisting only of pure value
> types) this is straightforward. If a reference type is involved, put
> the contents in the static data segment and have the enum value
> referencing this one instance. I presume this can be done...?
>
> Stewart.
More information about the Digitalmars-d
mailing list