Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What do i64 and i32 at the end of the values in limits.h mean?

Tags:

c

I was looking at limits.h on windows and found this:

#define LLONG_MAX     9223372036854775807i64       // maximum signed long long int value
#define LLONG_MIN   (-9223372036854775807i64 - 1)  // minimum signed long long int value
#define ULLONG_MAX    0xffffffffffffffffui64       // maximum unsigned long long int value

What does the i64 at the end of the value mean?

like image 347
PHANIX Avatar asked Aug 25 '18 06:08

PHANIX


People also ask

What is i64 in C?

The i64 suffix is a Microsoft extension to specify 64-bit integer constants. A portable alternative is (int64_t)9223372036854775807 , but older versions of Microsoft C did not support C99 <stdint.

Is i64 long?

Interstate 64 (I-64) is an Interstate Highway in the US state of West Virginia. It travels through the state for 184 miles (296 km) passing by the major towns and cities of Huntington, Charleston, Beckley, and Lewisburg.

What is unsigned long long?

An unsigned version of the long long data type. An unsigned long long occupies 8 bytes of memory; it stores an integer from 0 to 2^64-1, which is approximately 1.8×10^19 (18 quintillion, or 18 billion billion). A synonym for the unsigned long long type is uint64 .


1 Answers

The i64 suffix is a Microsoft extension to specify 64-bit integer constants.

A portable alternative is (int64_t)9223372036854775807, but older versions of Microsoft C did not support C99 <stdint.h> types.

You can also use the standard suffix LL to specify a constant of of type long long, which has at least 63 value bits, but may have more on some platforms. The case of L is not significant, so 1ll is equivalent to 1LL, but significantly more confusing because l looks a lot like 1, especially with some fixed type fonts.

Note that 9223372036854775807 as an integer constant has the smallest type with enough range to express it in the list int, long int, long long int. Given the common sizes for these types on Microsoft platforms, the type long long int is probably the only one with 64-bits.

The suffix is more useful for smaller constants such as 1 as show below:

uint64_t x = 1 << 32;     // undefined behavior
uint64_t x = 1ULL << 32;  // fully defined, x is 0x800000000
uint64_t x = 1ui64 << 32; // Microsoft specific, non portable
like image 108
chqrlie Avatar answered Nov 05 '22 05:11

chqrlie