简体   繁体   中英

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

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

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 , and
  • sizeof(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!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM