strong enums: why implicit conversion to basetype?

Manfred Nowak svv1999 at hotmail.com
Thu Jan 26 09:18:37 PST 2012


Trass3r wrote:


> Even typedef implicitly converts in one of the directions.

`typedef' is or will be disallowed in D because of reasons I do not 
understand. In C and C++ their existence introduce problems because 
they increase the amount of parsing passes. 


> A named enum is a separate type with a finite set of allowed 
> values defined by the user.
A)
Both wrong according to the currently published reference:

1) "The enum EnumTag declares a new type, and all the EnumMembers have 
that type.", i.e. it is the tag not the hole enum that produces a new 
type. 
2) "Enum declarations are used to define a group of constants.", i.e. 
only some of the valid values of the basetype are given names. All of 
the valid values of the basetype are also valid in the type declared 
by the tag.
3) "An EmptyEnumBody signifies an opaque enum - the enum members are 
unknown", i.e. none of the valied values of the basetype has got a 
name, but all valid values of the basetype are also valid in the type 
declared by the tag.

B)
It is somehow difficult to write about the reference because the use 
of the terms declaration, definition or declaration follows rules, 
which I have not yet detected.

I use "declaration" for any entity, which is undefined at the current 
position of reading _and_ will be defined after that position is 
passed. This is often an identifier in D.  

I use "definition" for any entity, which represents the content of the 
transition from undefined to defined. This is often a type in D. 

I use "specification" for those two entities, which represents a 
binding between a declaration and a definition. This is often the 
absence of operators in D.

-manfred


More information about the Digitalmars-d mailing list