Check out this quote from here, towards the bottom of the page. (I believe the quoted comment about const
s apply to invariant
s as well)
Enumerations differ from consts in that they do not consume any space in the final outputted object/library/executable, whereas consts do.
So apparently value1
will bloat the executable, while value2
is treated as a literal and doesn't appear in the object file.
const int value1 = 0xBAD;
enum int value2 = 42;
Back in C++ I always assumed this was for legacy reasons, and old compilers that couldn't optimize away constants. But if this is still true in D, there must be a deeper reason behind this. Anyone know why?