What determines the size of an integer?

sizeof(int) shows 4 on my Dev Cpp , although it works on a 64-bit machine. Why doesn't he review the base HWs and show 8 instead? In addition, if compilation of the environment also changes to 64 bits (does 64 bit compiler make sense in the first place ?!), would the int size change?

Are there any standards that solve this?

+4
c compiler-construction sizeof 64bit
Mar 13 2018-12-12T00:
source share
2 answers

Taken from http://en.wikipedia.org/wiki/64-bit (under 64-bit data models )

There are various models, Microsoft decided that sizeof(int) == 4 , some (some) others did not.

The Solaris HAL computer port for SPARC64 and Unicos seems to be the only port where sizeof(int) == 8 . They are called ILP64 and SILP64 models.

The true β€œwar” was for sizeof(long) , where Microsoft decided to use sizeof(long) == 4 (LLP64), and almost everyone decided for sizeof(long) == 8 (LP64).

Please note that this is actually a compiler that "decides" which model to use, but as written in the wiki

Note that the programming model is a choice made for each compiler, and several may coexist on the same OS. However, the programming model chosen as the primary model for the OS API usually dominates.

+14
Mar 13 '12 at 17:34
source share

While the compiler ultimately decides the size of the integer, it is usually inherited as the size of the processor registers that will contain the integer. Many processors support 32-bit / 64-bit register arithmetic, and compiler settings determine which mode is invoked. Since sizeof (long), etc., the only guarantee is sizeof (long)> = sizeof (short).

0
Apr 28 '17 at 8:15
source share



All Articles