The integer size in C

Does the ANSI C specification for int size equal the word size (32 bit / 64 bit) of the system?

In other words, can I decipher the size of the system word based on the space allocated for int ?

+2
c sizeof specifications
source share
4 answers

The size of the int type is implementation dependent, but cannot be shorter than 16 bits. See the Minimum Type Limits section here .

This Linux kernel development site claims that the long type is guaranteed to be the size of a machine word, but this operator is likely to be false: I could not find confirmation in the standard, and long has a width of only 32 bits on Win64 systems (since on these systems using the LLP64 data model ).

+6
source share

The language specification recommends that int have a natural word size for the hardware platform. However, this is not strictly required. If you noticed that to simplify the transition from 32-bit to 64-bit code, some modern implementations prefer to save int as a 32-bit type, even if the underlying hardware platform has a 64-bit word size.

And as Frederick has already noted, in any case, the size cannot be less than 16 bits of the formation of values.

+3
source share

The original int value would be the size of the word โ€” the most efficient data processing size. However, all that has a tendency is that a huge amount of code is written, assuming that the size of the int is X bits, and when the hardware on which the code is executed moves to a larger word size, the carelessly written code will break . Compiler vendors should keep their customers happy, so they say, "OK, we will leave the int size as before, but now we will do a lot more." Or, "ahhh ... too many people complained that we will make longer longer, we will create a long long type, leaving sizeof (int) == sizeof (long)". So these days it's all a mess:

Does the ANSI C specification define an int size equal to the word size (32 bit / 64 bit) of the system?

Pretty much an idea, but it doesn't insist on it.

In other words, can I decipher the size of the system word based on the space allocated for int?

Not in practice.

+1
source share

You should check your system limit.h file. The INT_MAX declaration should help you get back to calculating what is the minimum size an integer should have. See http://www.opengroup.org/onlinepubs/009695399/basedefs/limits.h.html for more details.

0
source share

All Articles