Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

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.

j specifies that a following d, i, o, u, x, X, or n conversion specifier applies

...

to an argument with type pointer to intmax_t or uintmax_t.

t Specifies that a following d, i, o, u, x, X, or n conversion specifier applies to an argument with type pointer to ptrdiff_t or the corresponding unsigned integer type.

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