manifest enum
Sean Kelly
sean at f4.ca
Tue Jan 1 16:07:17 PST 2008
John Reimer wrote:
> Sean Kelly wrote:
>
>> 'enum' is now basically a storage class in addition to an enumeration
>> specifier, so you can even do this I believe:
>>
>> enum:
>> a = 1;
>> b = 2;
>>
>>
>> Sean
>
>
> I'll have to test it out and see (that must have been based on earlier
> discussions?).
>
> But doing that would seem strange... and maybe a little ambiguous? What
> marks the end of the "enum:" specifier sequence for manifest constants
> then?
The end of the scope I think. And I should qualify this by saying I
haven't tried it, but it would be consistent with what Walter has said
in the past. So far, the only slightly tricky thing I've found is where
the new behavior overlaps the old behavior:
enum
{
a = byte.max
}
In D 1.0, the type of 'a' is int, and in D 2.0 the type is 'byte',
because the type in D 2.0 is inferred from the initializer. So for
portability, such declarations should always be specified with a type
qualifier:
enum : int
{
a = byte.max
}
Fortunately, implicit narrowing conversions seem to be disallowed in D
1.0 here, so this is illegal and thus not a portability problem:
enum
{
a = long.max
}
It's legal in D 2.0 however, and the resulting type is 'long', as you'd
expect.
Sean
More information about the Digitalmars-d
mailing list