Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is intmax_t the same as long long int?

Tags:

c

posix

By POSIX, intmax_t designates a signed integer type capable of representing any value of any signed integer type.

Would it be correct that in C99/C11 that intmax_t is always the same size as long long int?

like image 409
countunique Avatar asked Dec 08 '13 21:12

countunique


People also ask

What is Intmax_t?

The intmax_t is the longest integer type in C – it's the same as the long or the long long type. The absolute value of a number ( n ) is the non-negative value of n . In mathematics, we denote the absolute value as below: The absolute value of both n and -n is n.

Is there something bigger than Long Long C++?

No, but you can use libraries like GMP to handle bigger numbers.

Is long longer than int?

The int data type is a 32-bit signed two's complement integer. The long data type is a 64-bit signed two's complement integer. The long is a larger data type than int. The difference between int and long is that int is 32 bits in width while long is 64 bits in width.


3 Answers

No. intmax_t can be an extended integer type larger than long long. I'm not aware of any systems that have it defined as such, but you should not assume in application code that they're the same. (Assuming they're the same in OS code may be acceptable if your OS always guarantees that, but it's still probably a bad idea.)

like image 68
R.. GitHub STOP HELPING ICE Avatar answered Sep 30 '22 05:09

R.. GitHub STOP HELPING ICE


C99 N1256 standard draft

6.2.5 Types tells us about "extended signed integer types":

4 There are five standard signed integer types, designated as signed char, short int, int, long int, and long long int. (These and other types may be designated in several additional ways, as described in 6.7.2.) There may also be implementation-defined extended signed integer types The standard and extended signed integer types are collectively called signed integer types. 29)

29) Therefore, any statement in this Standard about signed integer types also applies to the extended signed integer types.

7.18.1.5 Greatest-width integer types says that intmax_t is the largest possible "signed integer type", thus including extended ones:

1 The following type designates a signed integer type capable of representing any value of any signed integer type:

intmax_t

6.4.4.1 Integer constants then makes it pretty clear that the extended integer types might be larger than any of the standard ones:

6 If an integer constant cannot be represented by any type in its list, it may have an extended integer type, if the extended integer type can represent its value.


If long and long long have the same width and representation, which they often do, long could be chosen for intmax_t.

like image 35
Jens Gustedt Avatar answered Sep 30 '22 03:09

Jens Gustedt