enum value vs. immutable
Sergei Nosov
sergei.nosov at gmail.com
Sun Dec 1 23:31:55 PST 2013
On Monday, 2 December 2013 at 05:57:33 UTC, CJS wrote:
> I was reading the enum page of Ali Çehreli's (excellent) D book
> (http://ddili.org/ders/d.en/enum.html), and I'm confused by an
> enum value (not enum type), such as
> enum secondsPerDay = 60 * 60 * 24;
> In that situation I would have used an immutable variable. Is
> there any reason to prefer enum vs. immutable when defining
> constants?
enum is a compile-time constant and an immutable variable is not.
As an example, in order to create a enum variable you have to
know it's value at compile time, e.g. you can't read it from
file. On the contrary, you can read a string from file and string
is the same thing as immutable(char) in D.
More information about the Digitalmars-d-learn
mailing list