K
Keith Thompson
jacob navia said:Le 23/05/11 23:25, Ian Collins a écrit :
True, but the PURPOSE of typedefs is to HIDE the underlying type so that
source code refers to it INDIRECTLY.
The purpose of that indirection is twofold:
(1) To highlight a CONCEPT of the program:
typedef double CustomerBalance;
(2) To make code portable by abstracting the underlying type
away. (size_t for instance)
The purpose of a typedef is whatever the programmer wants to use it for.
It can be used simply to provide a shorter name for an existing type.
For example:
typedef unsigned long ulong;
typedef struct foo {
/* member declarations */
} foo;
Neither ulong nor foo provides an abstraction; they're both just
aliases.
Typedefs can certainly be *used* for the purposes you describe,
and a tutorial can and should discuss that. But if you want your
readers to understand the concept, I suggest that that should
include an understanding of what typedef means on the language level.
You are conflating the manner in which typedef is *used* with the
way the language defines it.
Incidentally, I've said that a typedef is an alias, and you've agreed
that that's what it does (see above), yet you insist that I'm wrong.
I think we're actually in agreement. Perhaps you'd be able to
acknowledge that if this were coming from someone other than me.