In C and C++, the size of the build-in integer types is implementation dependent. But is there any predefined intended meaning of them such that int should represent the machine word size etc?
In C and C++, the size of the build-in integer types is implementation dependent.
Share
Historically,
intwas supposed to mean the most “natural” type for aninteger on the machine hardware; obviously, “natural” is somewhat
subjective, but in the past, it was usually pretty obvious, and there
weren’t that many integral types available anyway, so makeing
intthesame size as a
longor ashortwas the normal course of things.For various reasons, most 64 bit platforms make
int32 bits. Onecould easily argue that this isn’t the most “natural” length, but there
was a desire that 32 bit integers be the default, and
intis clearlythe default integral type. Whether it is the most natural for the
architecture or not becomes secondary to whether it is the size wanted
as a default.
With regards to word size: historically, this was the most natural, but
in many ways, it’s not clear what is meant by “word size” on a modern
machine: the largest size you can do arithmetic on? the size of bus
transfers to and from memory? etc. Traditionally, “word size” has been
used to mean both the width of internal registers (when the machine had
them), or the size of a basic bus transfer. (The 8088 was usually
referred to as an 8 bit machine, although it had 32 bit registers.) I
wouldn’t put too much meaning in it today.