more enum and pragma troubles

captaindet 2krnk at gmx.net
Fri Aug 16 23:51:32 PDT 2013


[enum foo = Test.test2;]

On 2013-08-17 01:03, JS wrote:
>> pragma( msg, foo ); // why does it print: cast(Test)2
>> // it should be: test2
>> // or at least simply: 2
>>
>
> It is 2! Notice the 2 at the end? The cast is just mumbo jumbo due to
> the the compiler deals with the stuff. You can remove the casts
> manually if you don't like them.

i saw the 2, but foo semantically contains a Test Test.test2 (this is the idea) or technically an int 2. don't understand why pragma displays an explicit cast here. maybe some internals that are leaking through the pragma(msg,...) implementation.


>> // pragma( msg, bar ); // Error: variable bar cannot be read at compile time
>>
>
> Because bar is not a compile time constant. It is an runtime object.
> pragma can't display certain things that it doesn't know about due to
> the way the compiler works. It's unfortunate in some cases that it
> simply doesn't work correctly, in others, such as this, it works as
> expected.
> You could argue that the compiler should know that bar is known at
> compile time up to the pragma, and I would agree... but the compiler
> simply isn't that smart.

but this is my very point! 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. where is it documented that named enums become runtime objects?

but you are right that this seems to be the case here and that pragma(msg,...) is off the hook this time:

enum Test{
	test2 = 2,
	test4 = 4
}
enum foo = Test.test2;
Test bar = Test.test4;
//  enum wtf = bar; 	// Error: variable bar cannot be read at compile time


/det


More information about the Digitalmars-d-learn mailing list