简体   繁体   中英

Do int8_t, int16_t, int32_t and int64_t have same respective ranges on different C++ compilers?

Or this is dependent on the 16 bit, 32 bit, etc. compiler?

Also, are these data types valid in C, C# or Java?

The C++ Standard requires that int8_t , int16_t , int32_t , and int64_t be exactly the specified width, with unsigned counterparts prefixed with u , only if such types exist on the target platform . And yes, these are valid, standard types in C. Java and C# contain no such integral data types of the same names.

Related types are intN_least_t and intN_fast_t , where the "least" types have at least the number of bits specified.

intN_t is a exact-width integer type of N bits long. Per the C11 draft N1570 7.2.1.1 they are defined as:

The typedef name intN_t designates a signed integer type with width N, no padding bits, and a two's complement representation. Thus, int8_t denotes such a signed integer type with a width of exactly 8 bits.

However

These types are optional. However, if an implementation provides integer types with widths of 8, 16, 32, or 64 bits, no padding bits, and (for the signed types) that have a two's complement representation, it shall define the corresponding typedef names.

These types are valid in C and C++. The reason we have these as normal short , int , and long long have no guarantees on their size except for a minimum range

In C# this would be equivalent to the Int16 , Int32 and Int64 types. In Java we can use byte , short , int and long as those are all guaranteed to be of an exact width.

They have same range based on std C++. More details here

and They are valid on C, but not sure on Java and C#

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