Discussion:
typedef vs inheritance
(too old to reply)
Carmen Sei
2008-04-17 01:23:10 UTC
Permalink
I found in C++ a type is typedef several times and alot of time, I
need to dig further to see the original type.

like LPDWORD - it's a strange type, but when i dig further, i see it's
a (DWORD *)

===========
typedef DWORD near *PDWORD;
typedef DWORD far *LPDWORD;

===========
i feel that creating new type in C++ by using "typedef" is similar to
inheritance in Java -

where alot of time I need to dig further to found the "PARENT" type of
an object hierarchy.
Doug Harrison [MVP]
2008-04-17 01:48:25 UTC
Permalink
Post by Carmen Sei
I found in C++ a type is typedef several times and alot of time, I
need to dig further to see the original type.
like LPDWORD - it's a strange type, but when i dig further, i see it's
a (DWORD *)
===========
typedef DWORD near *PDWORD;
typedef DWORD far *LPDWORD;
===========
i feel that creating new type in C++ by using "typedef" is similar to
inheritance in Java -
The C++ typedef keyword is used to create synonyms for existing types. It's
got nothing to do with inheritance.
Post by Carmen Sei
where alot of time I need to dig further to found the "PARENT" type of
an object hierarchy.
True, you're digging, but for different things.
--
Doug Harrison
Visual C++ MVP
Carmen Sei
2008-04-17 05:05:17 UTC
Permalink
why create some many synonyms of existing types.

that create great confusion like -
typedef DWORD far *LPDWORD;

what LPDWORD is? not until u need to dig further to find out it's
DWORD*.
Post by Doug Harrison [MVP]
The C++ typedef keyword is used to create synonyms for existing types. It's
got nothing to do with inheritance.
Post by Carmen Sei
where alot of time I need to dig further to found the "PARENT" type of
an object hierarchy.
True, you're digging, but for different things.
Ulrich Eckhardt
2008-04-17 07:42:22 UTC
Permalink
Post by Carmen Sei
why create some many synonyms of existing types.
that create great confusion like -
typedef DWORD far *LPDWORD;
what LPDWORD is? not until u need to dig further to find out it's
DWORD*.
In fact it's not, or rather it used not to be. The point is that 'L' means
long and 'P' means pointer. In ye olde memorey modell, there used to be a
distinction between near and far pointers, which had to do with segmented
memory. So, there, you always had to specify which type of pointer you
meant, which caused quite some typing overhead, so people invented those
shortcuts. The 'L' is nowadays obsolete, and a simple PDWORD should also
work, but often you still see the form with the 'L'. BTW: another
often-used one is 'C' which means 'const'.

Please don't top-post.

Uli
--
C++ FAQ: http://parashift.com/c++-faq-lite

Sator Laser GmbH
Geschäftsführer: Michael Wöhrmann, Amtsgericht Hamburg HR B62 932
Jonathan Wood
2008-04-18 16:17:21 UTC
Permalink
A lot of those relate to creating various definitions for compatibility with
older code, and in some cases new libraries.

For example, under the 16-bit compiler, far and near were keywords. Now
they're defines that serve no purpose other than to allow code that uses
them to still compile.

It's just to make things easier in some cases. That's all.
--
Jonathan Wood
SoftCircuits Programming
http://www.softcircuits.com
Post by Carmen Sei
why create some many synonyms of existing types.
that create great confusion like -
typedef DWORD far *LPDWORD;
what LPDWORD is? not until u need to dig further to find out it's
DWORD*.
Post by Doug Harrison [MVP]
The C++ typedef keyword is used to create synonyms for existing types. It's
got nothing to do with inheritance.
Post by Carmen Sei
where alot of time I need to dig further to found the "PARENT" type of
an object hierarchy.
True, you're digging, but for different things.
Joseph M. Newcomer
2008-04-20 20:47:07 UTC
Permalink
Why not? Having a single name to type is simpler than having to constantly type the *.

Ignore the word 'far', it has no meaning. In a rational world, the existence of this word
would have been expunged in about 1988 when Windows NT 3.1 was being created. But they
keep letting it hang around. And it smells.
joe
Post by Carmen Sei
why create some many synonyms of existing types.
that create great confusion like -
typedef DWORD far *LPDWORD;
what LPDWORD is? not until u need to dig further to find out it's
DWORD*.
Post by Doug Harrison [MVP]
The C++ typedef keyword is used to create synonyms for existing types. It's
got nothing to do with inheritance.
Post by Carmen Sei
where alot of time I need to dig further to found the "PARENT" type of
an object hierarchy.
True, you're digging, but for different things.
Joseph M. Newcomer [MVP]
email: ***@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm

Loading...