Search code examples
cintsizeof8-bit

Size of int on 8-bit machines


The ISO C standard states that A "plain" int object has the natural size suggested by the architecture of the execution environment

However, it is also guaranteed that int is at least as large as short, which is at least 16 bits in size.

The natural size suggested by an 8-bit processor, such as a 6502 or 8080, would seem to be an 8-bit int, however that would make int shorter than 16 bits. So, how large would int be on one of these 8 bit processors?


Solution

  • From Section 6.2.5 Types, p5

    5 An object declared as type signed char occupies the same amount of storage as a ''plain'' char object. A ''plain'' int object has the natural size suggested by the architecture of the execution environment (large enough to contain any value in the range INT_MIN to INT_MAX as defined in the header <limits.h>).

    And 5.2.4.2.1 Sizes of integer types <limits.h> p1

    Their implementation-defined values shall be equal or greater in magnitude (absolute value) to those shown, with the same sign.

    ...

    • minimum value for an object of type int

      INT_MIN -32767 // -(215 - 1)

    • maximum value for an object of type int

      INT_MAX +32767 // 215 - 1

    Then in those platforms, int must be at least 16 bits