Solaris 7 64-bit Developer's Guide

Format String Macros

Macros for specifying the printf(3S) and scanf(3S) format specifiers are also provided in <inttypes.h> . Essentially, these macros prepend the format specifier with an l or ll to specify the argument as a long or long long, given that the number of bits in the argument is built into the name of the macro.

Macros for printf(3S) format specifiers exist for printing 8-bit, 16-bit, 32-bit, and 64-bit integers, the smallest integer types, and the biggest integer types, in decimal, octal, unsigned, and hexadecimal. See the examples that follow.


Example 4-1

int64_t i;
printf("i =%" PRIx64 "\n", i);

Similarly, there are macros for scanf(3S) format specifiers for reading 8-bit, 16-bit, 32-bit, and 64-bit integers and the biggest integer type in decimal, octal, unsigned, and hexadecimal.


Example 4-2

uint64_t u;
scanf("%" SCNu64 "\n", &u);

Do not use these macros indiscriminately. They are best used in conjunction with the fixed-width types. Refer to the section "Fixed-Width Integer Types " for more details.