more enum and pragma troubles

captaindet 2krnk at gmx.net
Sun Aug 18 21:37:57 PDT 2013


On 2013-08-17 21:54, JS wrote:
> On Sunday, 18 August 2013 at 00:17:22 UTC, captaindet wrote:
>> On 2013-08-17 14:36, Jesse Phillips wrote:
>>> Third you've declared a variable, bar, which will store your
>>> enumerated value, 4. Variables are not compile time, even if the
>>> value stored came from a compile time known value.
>>
>> yep, it completely escaped me that these are 'normal' variables.
>> and i have realized now that i can make them known at compile time
>> the same way as is done for other 'normal' variables, by declaring
>> them const ;)
>>
>
> But if they are const then what good does that do you? Just use an
> alias or enum in the first place?

to be honest, i have not found a use case ;)

highest priority was that i understood what was going on here...

how did i get there? i was looking for an easy way to get pragma(msg,...) to print the given name for an enumerated value. in this example test2 or test4 instead of 2 and 4 - just like write is doing it at runtime. so i was playing around with the different variants of enum to see if i could get it working somehow.. and got sidetracked....

in the end i stuck to manifest constant enums storing the enumerated values and found that

pragma( msg, to!string(foo) );

is doing the trick.


/det


More information about the Digitalmars-d-learn mailing list