What is the difference between __int <size> and "char, short, int, long long int"?

I was surprised to see that my C ++ compiler supports __int8

, __int16

, __int32

and __int64

; But I just see that 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

      

+3


source to share


1 answer


The dimensions of the primitive types int

, char

, short

, long

, etc. are implementation-defined and may vary from system to system. All you are guaranteed is that

  • sizeof(char) == 1

    and
  • sizeof(char) <= sizeof(short) <= sizeof(int) <= sizeof(long)

    ...


As a result, many platforms provide their own, non-portable types that are guaranteed to be sizing. For example, I'm pretty sure Microsoft guarantees that it is __int8

always eight bits, __int16

always 16 bits, etc.

Hope this helps!

+5


source







All Articles