www.digitalmars.com         C & C++   DMDScript  

D - typedef and alias

reply "Ben Hinkle" <bhinkle4 juno.com> writes:
Can a different word be used instead of "typedef" for D's typedef? I think
it is asking for confusion when "alias" is equivalent to C's typedef (though
I support one can alias more things than just types, right?) and D makes
"typedef" mean something else. Since I speak C/C++ much more often than D I
have the word "typedef" hard-wired in my brain to mean what it has always
meant.
I think it would be easier on us C programmers to either make typedef mean
C's typedef or change the name to not conflict with C's typedef.

-Ben
Nov 19 2003
parent Berin Loritsch <bloritsch d-haven.org> writes:
Ben Hinkle wrote:

 Can a different word be used instead of "typedef" for D's typedef? I think
 it is asking for confusion when "alias" is equivalent to C's typedef (though
 I support one can alias more things than just types, right?) and D makes
 "typedef" mean something else. Since I speak C/C++ much more often than D I
 have the word "typedef" hard-wired in my brain to mean what it has always
 meant.
 I think it would be easier on us C programmers to either make typedef mean
 C's typedef or change the name to not conflict with C's typedef.

Playing devil's advocate here: Why have both typedef and alias at all? Simplify. Have one word to mean you are making a new type, even if the scope of the type would be for one class/module. If you have it as an "alias", it is sufficiently different from C/C++ to make it known it operates differently. The alias would be a new type, but the compiler will create automatic conversion (aka casting) for the original type. For instance: alias Rectangle<float> Rect; would mean that we can do the following: Rect myRect = (Rect) new Rectangle<float>(); or Rectangle<float> outsideRect = (Rectangle<float>) new Rect(); That way the types can still be used interchangably, but treated as a strong type. Do we really need both a typedef and an alias? I think it is overkill.
Nov 19 2003