7.8.1 Macros for format specifiers

1

Each of the following object-like macros[1] expands to a character string literal containing a conversion specifier, possibly modified by a length modifier, suitable for use within the format argument of a formatted input/output function when converting the corresponding integer type. These macro names have the general form of PRI (character string literals for the fprintf and fwprintf family) or SCN (character string literals for the fscanf and fwscanf family),[2] followed by the conversion specifier, followed by a name corresponding to a similar type name in 7.18.1. In these names, N represents the width of the type as described in 7.18.1. For example, PRIdFAST32 can be used in a format string to print the value of an integer of type int_fast32_t.

2

The fprintf macros for signed integers are:

PRIdN             PRIdLEASTN                PRIdFASTN          PRIdMAX             PRIdPTR
PRIiN             PRIiLEASTN                PRIiFASTN          PRIiMAX             PRIiPTR

3

The fprintf macros for unsigned integers are:

PRIoN           PRIoLEASTN               PRIoFASTN              PRIoMAX             PRIoPTR
PRIuN           PRIuLEASTN               PRIuFASTN              PRIuMAX             PRIuPTR
PRIxN           PRIxLEASTN               PRIxFASTN              PRIxMAX             PRIxPTR
PRIXN           PRIXLEASTN               PRIXFASTN              PRIXMAX             PRIXPTR

4

The fscanf macros for signed integers are:

SCNdN           SCNdLEASTN               SCNdFASTN              SCNdMAX             SCNdPTR
SCNiN           SCNiLEASTN               SCNiFASTN              SCNiMAX             SCNiPTR

5

The fscanf macros for unsigned integers are:

SCNoN           SCNoLEASTN               SCNoFASTN              SCNoMAX             SCNoPTR
SCNuN           SCNuLEASTN               SCNuFASTN              SCNuMAX             SCNuPTR
SCNxN           SCNxLEASTN               SCNxFASTN              SCNxMAX             SCNxPTR

6

For each type that the implementation provides in <stdint.h>, the corresponding fprintf macros shall be defined and the corresponding fscanf macros shall be defined unless the implementation does not have a suitable fscanf length modifier for the type.

7

EXAMPLE

#include <inttypes.h>
#include <wchar.h>
int main(void)
{
      uintmax_t i = UINTMAX_MAX;    // this type always exists
      wprintf(L"The largest integer value is %020"
            PRIxMAX "\n", i);
      return 0;
}

Footnotes