7.8.1 Macros for format specifiers
1 Each of the following object-likemacros
191)
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),
192)
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. Forexample, 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
190) See ‘‘future library directions’’(7.26.4).
191) C++ implementations should define these macros only when __STDC_FORMAT_MACROS is defined
before <inttypes.h> is included.
192) Separate macros are givenfor use with fprintf and fscanf functions because, in the general case,
different format specifiers may be required for fprintf and fscanf,evenwhen the type is the
same.
198 Library §7.8.1WG14/N1256 Committee Draft — Septermber 7, 2007 ISO/IEC 9899:TC3
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 Foreach 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;
Partager