Andrew Tomazos
Andrew Tomazos

Reputation: 68698

What should `intmax_t` be on platform with 64-bit `long int` and `long long int`?

In the C++ standard 18.4 it specifies:

typedef 'signed integer type' intmax_t;

By the standard(s) on a platform with a 64-bit long int and a 64-bit long long int which should this "signed integer type" be?

Note that long int and long long int are distinct fundamental types.

The C++ standard says:

The header defines all functions, types, and macros the same as 7.18 in the C standard.

and in 7.18 of the C standard (N1548) it says:

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

intmax_t

It would seem that in this case that both long int and long long int qualify?

Is that the correct conclusion? That either would be a standard-compliant choice?

Upvotes: 6

Views: 1744

Answers (2)

wallyk
wallyk

Reputation: 57784

Well, assuming the GNU C library is correct (from /usr/include/stdint.h):

/* Largest integral types.  */
#if __WORDSIZE == 64
typedef long int                intmax_t;
typedef unsigned long int       uintmax_t;
#else
__extension__
typedef long long int           intmax_t;
__extension__
typedef unsigned long long int  uintmax_t;
#end

Upvotes: 3

R.. GitHub STOP HELPING ICE
R.. GitHub STOP HELPING ICE

Reputation: 215387

Yes, your reasoning is correct. Most real-world implementations choose the lowest-rank type satisfying the conditions.

Upvotes: 6

Related Questions