D
Douglas A. Gwyn
Keith said:The fundamental problem, I think, is that C's integer type system
isn't uniform enough. The type names are all keywords or sequences of
keywords with a very limited grammar, and it's far too easy for unwary
programmers to create dependencies on certain types being certain
sizes.
All width dependencies should be expressd in terms of the
<stdint.h> typedefs.
It is certainly true that as machines have grown, C's type
system has become strained. It already caused trouble when
C89 legislated sizeof(char)==1, making it necessary to add
a whole duplicate set of character/string facilities.
Another problem is that as a historical artifact of the way
the PDP-11 implementation worked, the smallest types get
promoted to intermediate sizes way too readily. Personally
I'm not a fan of "mixed mode arithmetic", preferring that
all conversions be explicit, but that's not going to happen
for C. The integer promotion rules are a problem when
introducing new integer types, and there was quite an
argument about what they should be for long long and the
(optional) extended integer types.
We discussed for a while the possibility of adding much
better support for "requirements-based integer type
specification", including endianness, representation, and
other attributes as well as the usual signedness and width,
but it was deemed too radical a change to be making until
we have seen results from a similar experimental
implementation (which we encouraged, but haven't yet seen).
We were able to agree upon <inttypes.h> and <stdint.h> due
to there being sufficient existing practice to judge its
merits. Now all we have to do is to get some recalcitrant
folks to use them when appropriate, i.e. work with us
instead of fighting us.
One possible solution that's consistent with what's been done so far
might be to allow a "short short" type. ...
(and maybe "long char" rather than "wchar_t").
In 1986 I proposed "short char" as the unit for sizeof.
At the time some new computer architectures were being
designed, and many of us wanted to see direct bit
addressability, but lacking any way to get at it from
portable high-level languages, management wouldn't allow
it.
While we could still add more general integer type
specification to C, it is really too late to fix all its
problems. I sincerely hope that designers of future
procedural programming languages will learn from the
mistakes of the past and do it right, but experience
suggests otherwise.