typedefs are useless
Steven Schveighoffer
schveiguy at yahoo.com
Mon Dec 3 11:07:28 PST 2007
"Kirk McDonald" wrote
>
> You can typedef things other than integral types.
OK, so that is one difference between enum and typedef (I forgot about that,
because I was so narrowly focused on my problem at hand).
but the same thing can be said for non-integral types:
typedef mytype float;
mytype x = 1.0 // does not work.
This typedef is just as useless as an integral typedef. The fact that enum
does not exist for a floating point type does not justify the existance of
typedef. You can use alias to make a more useful type, but you then do not
have the restrictions I am looking for.
I look at a typedef as a useful way to create a derived type from a builtin
type such that it is implicitly convertable to the base type, but not in
reverse (similar to deriving from a base class). However, without the
ability to specify literals, or even extend the syntax to be able to specify
them (i.e. some way to make 1mt mean cast(mytype)1), the type is only useful
as an enumeration, as any mathematical manipulation will require lots of
casting statements, just like an enum.
-Steve
More information about the Digitalmars-d
mailing list