2

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?

  • 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

1 Answers1

2

The size of int variable or any datatype's variable depends on the compiler. The compilers vendors decisions may be influenced by the current architectures. you can read this discussion to get more detail.

Community
  • 1
  • 1
LearningC
  • 3,182
  • 1
  • 12
  • 19