enum

Paulo Pinto pjmlp at progtools.org
Fri Apr 11 12:30:50 PDT 2014


Am 11.04.2014 20:32, schrieb Walter Bright:
> On 4/11/2014 4:18 AM, Jonathan M Davis wrote:
>> I don't see much point to enums if they're not intended to list
>> all of their values.
>
> Again, bit masks, Color, etc., and to provide a simple integral type
> that behaves like an integral type yet can be overloaded and type checked.
>
> Andrei has pointed out that these uses are unsound if you desire that
> the enumeration lists all possible values, and he's right. But I don't
> think that automatically makes them pointless.
>
> Heck, look at the "StorageClass" typedef in dmd's source code, and the
> list of STC macro definitions. That would make a nice D enum, and have
> some type safety too. It would be much more sound than the C method used.

Sure, but aren't those use cases a consequence of C's misuse of enums, 
which are handled better by numeric constants?

--
Paulo


More information about the Digitalmars-d mailing list