Reputation:
I am surprised to see also my C++ compiler supports __int8
, __int16
, __int32
, and __int64
; But I just see they are equivalent to char
, short
, int
, and long long
. What is the difference between them?
sizeof(__int8) == sizeof(char) == 1
sizeof(__int16) == sizeof(short) == 2
sizeof(__int32) == sizeof(int) == 4
sizeof(__int64) == sizeof(long long) == 8
Upvotes: 3
Views: 1324
Reputation: 372992
The sizes of the primitive types int
, char
, short
, long
, etc. are implementation-defined and can vary from system to system. All that you're guaranteed is that
sizeof(char) == 1
, andsizeof(char) <= sizeof(short) <= sizeof(int) <= sizeof(long)
.As a result, many platforms provide their own custom, non-portable types that are guaranteed to be the given sizes. For example, I am fairly confident that Microsoft guarantees that __int8
is always eight bits, __int16
is always 16 bits, etc.
Hope this helps!
Upvotes: 4