Re: typedef vs inheritance
On Apr 17, 7:10 am, Carmen Sei <fatwallet...@yahoo.com> wrote:
Then are you meaning
the following will compile only on Microsoft compiler but not other
C++ compiler?
typedef DWORD near *PDWORD;
typedef DWORD far *LPDWORD;
It's compiler specific added syntax (near / far) ??
It's definitely compiler specific added syntax, not standard,
and will not compile on any of the Unix compilers I use. As
Ivan said, it's a platform specific extension, and not part of
the standard language. It's an extension which addressed a very
real problem on 16 bit Intel processors, however, which was
present (in one form or another) in all compilers for that
platform, and could very well be present in their descendents on
Windows today (for reasons of backward compatibility). It
wouldn't surprise me to see it in the Borland compiler as well,
for example.
I'd also like to expond on Ivan's point about not abusing
typedef's. A typedef results in information hiding. A good
thing, if the information is irrelevant to the user; a bad thing
otherwise. Something like:
typedef int WidgitCount ;
, for example, is good: all I need to know about WidgitCount is
that it is a counter (which the name tells me)---perhaps on
another platform, or in the future, it will be long, or even
BigInt. Typedef's like the above, however, hide the fact that
you're dealing with a pointer. The fact that you're dealing
with a pointer, however, is important information---you don't
use a pointer like you'd use the value itself. (If I'm not
mistaken, DWORD is also a typedef. And also equally abusive.)
Most of the time, you'll probably find you want a class, rather
than a typedef. A class introduces a totally new type; it also
allows you to add validations to the operations. (Of course,
for simple things like WidgitCount, a class might be overkill.
Theoretically nicer, but a lot of extra code for a very small
benefit.)
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orient=E9e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S=E9mard, 78210 St.-Cyr-l'=C9cole, France, +33 (0)1 30 23 00 34