PhobosWatch: manifest => enum

Bastiaan Veelo Bastiaan at Veelo.net
Sun Dec 30 05:56:15 PST 2007


Derek Parnell wrote:
> On Sun, 30 Dec 2007 11:27:17 +0000, Janice Caron wrote:
> 
>> On 12/30/07, Bastiaan Veelo <Bastiaan at veelo.net> wrote:
>>> If not, that would be confusing to me, as you will
>>> be able to switch on some enums but not on others.
 >>
>> You can't switch on an anonymous enum. Anonymous enums have no type,
>> and therefore it is not even /possible/ to generate an expression
>> whose type is that of an anonymous enum!
>>
>> So switch/case survives unharmed.
> 
> And yet this compiles and runs ...
> 
> // -------------
> import std.stdio;
> 
> enum
> {
> one = 1,
> two = 2,
> three = 3
> }
> 
> void main()
> {
>     auto x = three;
>    
>     switch (x)
>     {
>         case one: writefln("ONE"); break;
>         case two: writefln("TWO"); break;
>         case three: writefln("THREE"); break;
>     }
> }     
> // -------------
> 

Yes, and although the extended enum would allow three to be defined as 
3f, then case three would not compile according to the current spec. 
That is obvious in this example, but it is a confusing inconsistency in 
the relation between enum and switch. enum and switch have always been 
compatible in my mind, but that is about to change...

Bastaan.



More information about the Digitalmars-d mailing list