C++ has no such type int32
, so I will assume you are referring to int32_t
. And to clear up some terminology, width usually refers to the number of bits wide a type is, and size refers to the number of bytes or chars a type is wide.
Yes, an int32_t
is required to be the same width, i.e., number of bits wide, on all platform that supports it, by definition. Exactly 32 bits wide. Do keep in mind that the type is optional and might not be defined at all, if and only if, the system does not have such a type, for example, if 32 is not a multiple of CHAR_BIT
.
But their size in bytes (as returned by the sizeof()
operator) depends on the value of CHAR_BIT
. That is, the number of bits in a byte. On most systems, a byte is 8 bits, so sizeof(int32_t)
will yield 4. But on an exotic system with 16-bit bytes, sizeof(int32_t)
will be only 2.