2
votes

For each signed integer type the Standard guarantees existence of a corresponding unsigned integer type. 6.2.5 p6:

For each of the signed integer types, there is a corresponding (but different) unsigned integer type (designated with the keyword unsigned ) that uses the same amount of storage (including sign information) and has the same alignment requirements.

The phrase designated with the keyword unsigned got me confused and I consulted with earlier versions of the Standard to understand if it was presented there. C89/3.2.1.5 provides exactly the same wording:

For each of the signed integer types, there is a corresponding (but different) unsigned integer type (designated with the keyword unsigned) that uses the same amount of storage (including sign information) and has the same alignment requirements.

Now consider uintptr_t and intptr_t; uintmax_t and intmax_t; etc... (which are optional, but in case an implementation defines those types).

QUESTION: According to the definition I cited above isn't uintptr_t a corresponding unsigned integer type for intptr_t and uintmax_t is a corresponding unsigned integer type for intmax_t?

I'm concerned about it because Usual arithmetic conversion uses the term 6.3.1.8 p1:

Otherwise, both operands are converted to the unsigned integer type corresponding to the type of the operand with signed integer type

So I'm trying to understand the semantic of the usual arithmetic conversion applied to, say, uintptr_t and intptr_t.

3
These are typedefs, not the actual types.Barmar
@Barmar Most likely, but it is not defined by the Standard AFAIK.St.Antario

3 Answers

3
votes

According to 7.20(4) these are typedef names, not the underlying types.

For each type described herein that the implementation provides,261) <stdint.h> shall declare that typedef name and define the associated macros.

And 7.20.1(1) says:

When typedef names differing only in the absence or presence of the initial u are defined, they shall denote corresponding signed and unsigned types as described in 6.2.5;

So I believe these are required to follow the same default conversion rules as the basic integer types are.

2
votes

The header in the Standard "7.20.1.5 Greatest-width integer types" and the description under the header where the two types are described in a pair assume that uintmax_t is defined as an unsigned type corresponding to the type intmax_t.

2
votes

The intN_t and uintN_t fixed width types weren't introduced until C99, so that may be why the standard you're referencing lacks information about them.