For example, I have an processor with 64-bit registers. Can it be 2 different compilers: one with size of int equals 32-bit and another with size of int equals 16-bit?
Asked
Active
Viewed 1,511 times
2
-
Short answer: yes. See also: http://stackoverflow.com/questions/11438794/is-the-size-of-c-int-2-bytes-or-4-bytes – Elmar Peise Mar 26 '14 at 17:54
-
It is the compiler that decides how big an int is. If you can run a 16 bit compiler on a 64 bit system, your ints will be 16 bits. – cup Mar 26 '14 at 17:54
-
It depends on whatever the compiler writer thought was a good choice. It used to be automatic and match the processor's register size. That's over and done with, memory is the constraint today. Lots of 64-bit compilers will use a 32-bit int. – Hans Passant Mar 26 '14 at 17:54
-
@HansPassant: Another rationale for making `int` 32 bits is that it allows 8, 16, 32, and 64 bits to be covered by the predefined types. If `char` is 8 bits and `int` is 64 bits, then `short` is (probably) either 16 or 32 bits, and the other size isn't covered. (Extended integer types are an option, though.) – Keith Thompson Mar 26 '14 at 18:03