Is typedef an alien?
Jeremie Pelletier
jeremiep at gmail.com
Thu Sep 24 12:11:48 PDT 2009
language_fan wrote:
> Thu, 24 Sep 2009 14:36:01 -0400, Aenigmatic thusly wrote:
>
>> No further response to any responses to my previous post's responses is
>> a both swift and non-invasive.
>>
>> Now my deeply thought question is ...
>>
>> Is typedef (in D) a C/C++ legacy or is the dear orphan now adopted as a
>> first-class citizen in the US of D?
>>
>> -- Yours truly, Justin Johansson
>
> Typedef works differently in D. It should create a new type, in C++ it's
> just a type synonym.
Exactly, it's most useful to create specialized types from primitives.
For example I declared the HANDLE type in my win32 bindings as "typedef
const(void)* HANDLE;" and all its specialized types (HWND, HMONITOR,
HDC, etc) are also typedefs of HANDLE, so I have very little chances of
misusing them. The only downside is that I must use HWND.init instead of
null, but that's just giving better readability to function calls.
This is something you just can't do in C.
More information about the Digitalmars-d
mailing list