AA literals/initialisation

Jonathan M Davis jmdavisProg at gmx.com
Mon Nov 11 15:55:50 PST 2013


On Monday, November 11, 2013 13:42:17 OneTwo wrote:
> enum - compile time constant
> immutable - run time constant

Not exactly. If they're global or static, then they both have to be known at 
compile time (though you can initialize an immutable global or static in a 
static constructor, which you can't do with an enum). The primary difference is 
that an immutable variable is actually a variable with a location in memory, 
where an enum is just a value that gets copy-pasted wherever it's used and is 
not associated with any particular location in memory. So, which you use tends 
to depend on whether you need it to be associated with a particular address in 
memory and whether you want its value to be copied everywhere.

- Jonathan M Davis


More information about the Digitalmars-d mailing list