D
Dan Pop
In said:Perhaps, but I think a lot of programmers would automatically
associate the name "myDouble" with C's type "double".
That would be a downright foolish association: no point in
*unconditionally* renaming a C keyword.
If I wanted to
create typedefs for small and large floating-point types, regardless
of what the C compiler chooses to call them, I might use terms like
"small_float" and "large_float" to avoid confusion.
I can still see no confusion with mySingle and myDouble. It is sheer
stupidity to assume anything a priori about a user defined identifier.
A typedef whose name is too close to a predefined type name is
probably either redundant (if it's for the same type) or confusing (if
it isn't).
For you, maybe. To me, it conveys the message: this type is, in most
cases, the same as the C type with a similar name, but it can be something
else on unusual implementations. See again my example with myDouble
ending up as being defined as long double on an exotic implementation,
while being defined as double on most other implementations.
To take another example, "typedef unsigned char byte;" is more
reasonable than "typedef unsigned char uchar;", IMHO.
To me, they are both unreasonable, being mere aliases for standard C
types. When I read C code, I'm much happier if I don't have to deal with
such devices (despite the obvious semantics, such typedef's MUST be
checked, to be *sure* that they really are what they appear to be).
(One might
argue that "typedef unsigned char byte;" is redundant, but I might use
such a typedef to distinguish between an unsigned char holding a
character value and an unsigned char holding a fundamental unit of
storage, a distinction that C's type system, for convoluted historical
reasons, doesn't make very well.)
The actual distinction is made by using the type char for dealing with
character values and the type unsigned char for dealing with bytes.
This is why the type char hasn't been made obsolete after the introduction
of the types signed char and unsigned char.
Dan