enums

Philippe Sigaud via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri May 30 10:17:15 PDT 2014


> In D enum can be used to define manifest constants. This means constants
> known at compile time. In practice for a double there isn't a lot of
> difference. In general you can't take the address of a manifest constant,
> unlike immutables.

Because they do not exist as 'variables' or symbol in the generated
code. They are directly replaced by their computed value.

so :

- enum : manifest constant, can be used as a template argument, as a
static if operand or generally as a compile-time value. Indeed, a way
to force compile-time function evaluation is to ask for an enum:

enum result = foo(...); // foo(...) will be evaluated during compilation.

- immutable : it's a real variable: you can initialize it (once) at
runtime, and take its address.


More information about the Digitalmars-d-learn mailing list