the preceding assignment should behave properly when compiled with any standard C compiler. If you declare d as some other integer type, such as

the assignment might provoke a warning from the compiler, or worse, silently truncate the assigned value at runtime, for example, if ptrdiff\_t were an alias for long long int for that implementation.

The lower and upper limits of ptrdiff\_t are defined by PTRDIFF\_MIN and PTRDIFF\_MAX respectively. The minimum acceptable limits defined by the C Standard are

These limits require that any 16-bit implementation must have at least a 17-bit ptrdiff\_t to represent all possible differences of 16-bit pointers.

Although the standard does not explicitly guarantee that sizeof(ptrdiff\_t) equals sizeof(size\_t), it typically is the case on 32-bit or 64-bit implementa-tions. This may seem somewhat surprising because a signed integer type may not be able to represent the difference between two pointers on such a system.

For example, on a system that supports objects up to \( 2 ^ { 3 2 } \mathrm { ~ - ~ } \) 1 bytes, the sizeof operator can yield values only from 0 to \( 2 ^ { 3 2 } - 1 \), so 32 bits are sufficient. However, pointer subtraction for pointers to elements of an array of \( 2 ^ { 3 2 } \mathrm { ~ - ~ } 1 \) bytes could yield values from −(232 − 1) to +(232 − 1). Consequently, ptrdiff\_t would have to be at least 33 bits to represent all possible differences. How-ever, C allows an implementation in which ptrdiff\_t is 32 bits by making it undefined behavior if the result of subtracting two pointers is not represent-able in an object of type ptrdiff\_t. In most cases, a ptrdiff\_t overflow on a two’s complement machine with quiet wraparound on overflow does not affect the result of the operation. To program securely, however, you should care-fully consider the consequences of your operation when the subtraction of two pointers may result in such large values.

intmax\_t and uintmax\_t. intmax\_t and uintmax\_t are integer types with the greatest width and can represent any value representable by any other inte-ger types of the same signedness. Among other applications, intmax\_t and uintmax\_t can be used for formatted I/O on programmer-defined integer types. For example, given an implementation that supports 128-bit unsigned integers and provides a uint\_fast128\_t type, a programmer may define the following type:

This creates a problem with using these types with formatted output functions, such as printf(), and formatted input functions, such as scanf(). For example, the following code prints the value of x as an unsigned long long, even though the value is of a programmer-defined integer type:

There is no guarantee that this code prints the correct value of x because x may be too large to represent as an unsigned long long.

The intmax\_t and uintmax\_t types are capable of representing any value representable by any other integer types of the same signedness, allowing conversion between programmer-defined integer types (of the same signed-ness) and intmax\_t and uintmax\_t:

Formatted I/O functions can be used to input and output greatest-width integer typed values. The j length modifier in a format string indicates that the following d, i, o, u, x, X, or n conversion specifier will apply to an argument with type intmax\_t or uintmax\_t. The following code guarantees that the cor-rect value of x is printed, regardless of its length, provided that mytypedef\_t is an unsigned type:

In addition to programmer-defined types, there is no requirement that an implementation provide format length modifiers for implementation-defined integer types. For example, a machine with an implementation-defined 48-bit integer type may not provide format length modifiers for the type. Such a machine would still have to have a 64-bit long long, with intmax\_t being at least that large. The CERT C Secure Coding Standard [Seacord 2008], “INT15-C. Use intmax\_t or uintmax\_t for formatted IO on programmer-defined integer types,” provides further examples of this use of the intmax\_t and uintmax\_t types.