sizeof(int)
shows 4 on my Dev Cpp
even though its running on a 64 bit machine. Why doesn't it consider the underlying HW and show 8 instead? Also, if I compiling environment also changes to 64 bit ( Does a 64 bit compiler
makes sense in the first place?! ), would size of int change then?
Are there any standards which decide this?
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 (a few) others didn't.HAL Computer Systems port of Solaris to SPARC64 and Unicos seem to be the only ones where
sizeof(int) == 8
. They are called ILP64 and SILP64 models.The true "war" was for
sizeof(long)
, where Microsoft decided forsizeof(long) == 4
(LLP64) while nearly everyone else decided forsizeof(long) == 8
(LP64).Note that in truth it's the compiler that "decides" which model to use, but as written in the wiki
While the compiler ultimately decides the size of an integer, it is usually inherited as the size of the CPU registers, that would hold the integer. Many processors support 32-bit/64-bit register arithmetic, and the compiler settings determine which mode is invoked. Insofar as sizeof(long), etc., the only guarantee is sizeof(long) >= sizeof(short).