S
santosh
user923005 said:The same arguments could have been made for 16 bit ints changing into
32 bit ints 'back in the day'.
Aren't you glad that they did not take that nonsense stance back then?
Ten years from now, 32 bit ints are going to look very foolish.
Especially when stdint.h gives you 32 bit sizes if you want them.
IMO-YMMV.
I must admit you are right though. The way the real world works *is*
broken.
The real world is practical. IMHO, int should reflect the most commonly
used integer ranges in most programs. A 32 bit int suits this. A 64 bit
int is perhaps an overkill. Just because the underlying processor's
registers have expanded doesn't mean that the most commonly used
integer type should also do so. The compiler can always put 32 bit
values into 64 bit registers for temporary calculations.
Ultimately it seems to me to be a elegance vs. space trade-off. I admit
that one a 64 bit system a 64 bit int type is very elegant and in
keeping with what Ritchie desired. But that's mean that int absolutely
*has* to mirror the processor GRP width. If other concerns are greater
then we could look at other models. After all, even if an int isn't 64
bits we can still use int64_t from stdint.h.
P.S.
From K&R2, p36:
"The intent is that short and long should provide different lengths of
integers where practical; int will normally be the natural size for a
particular machine. short is often 16 bits long, and int either 16 or
32 bits. Each compiler is free to choose appropriate sizes for its own
hardware, subject only to the the restriction that shorts and ints are
at least 16 bits, longs are at least 32 bits, and short is no longer
than int, which is no longer than long."
I think at the time Ritchie made this decision, he would probably have
little imagined that one day 64 bit systems would become the norm.
Particularly, one popular architecture supports a range of sizes from 8
to 16 to 32 to 64 and a lot of code and compilers have taken advantage
of this availability. Ritchie probably would have never imagined the
long long type, and I doubt he liked it's eventual creation, but it was
a practical necessity, as a very popular platform tied long to 32 bits.