more enum and pragma troubles
captaindet
2krnk at gmx.net
Sat Aug 17 00:14:50 PDT 2013
On 2013-08-17 01:51, captaindet wrote:
> my understanding was that enums are all compile time entities that
> are just copied around. at compile time. a named enum type should
> make no difference.
oh i see now, naming them is just creating a disguise for the base type. then they can become compile-time-known when declared const (see below). only anonymous enum (manifest constant) are true compile time objects. reminds me of my (type)tuple confusion. two completely different animals/concepts, with similar/confusing syntax and blurry docs.
module demo;
import std.stdio;
enum Test{
test2 = 2,
test4 = 4
}
enum foo = Test.test2;
const Test bar = Test.test4; // does the trick
enum wtf = bar;
pragma( msg, foo ); // prints: cast(Test)2
pragma( msg, bar ); // pritns: cast(Test)4
void main(){
writeln( typeof(foo).stringof, " = ", foo ); // prints: Test = test2
writeln( typeof(bar).stringof, " = ", bar ); // prints: const(Test) = test4
}
More information about the Digitalmars-d-learn
mailing list