By definition, the types intmax_t
and uintmax_t
are capable of representing any value representable by any other types of the same signedness. By using these types, the danger of truncation associated with the ambiguities of a change in platform or architecture, e.g. IA-32 to x86-64, can be mitigated.
Formatted input and output functions contain a length modifier which provides the above facilities for input/output. The j
specifier 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 pointer to intmax_t
or uintmax
Use the j
and t
length modifier in calls to scanf()
and printf()
for integer types where the underlying type is unknown but the signedness of the type is known. This includes types such as size_t
and ptrdiff_t
.
C99 Section 7.19.6.2, "The fscanf function" provides the following definitions for the j
and t
length modifiers.
...
C99 Section 7.18.1.5, "Greatest-width integer types"
The following type designates a signed integer type capable of representing any value of any signed integer type:
intmax_t
The following type designates an unsigned integer type capable of representing any value of any unsigned integer type:
uintmax_t
Use the
j
andt
length modifier in calls toscanf()
andprintf()
for integer types where the underlying type is unknown but the signedness of the type is known. This includes types such assize_t
andptrdiff_t
.