Wednesday, August 31, 2016

C Library Header – inttypes

The <inttypes.h> header provides features that enhance the functionality of the types defined in <stdint.h>

Printf format string - The macros are in the format PRI{fmt}{type}. Here {fmt} defines the output formatting and is one of d (decimal), x (hexadecimal), o (octal), u (unsigned) and i (integer). {type} defines the type of the argument and is one of N, FASTN, LEASTN, PTR, MAX, where N corresponds to the number of bits in the argument.

Scanf format string - The macros are in the format SCN{fmt}{type}. Here {fmt} defines the output formatting and is one of d (decimal), x (hexadecimal), o (octal), u (unsigned) and i (integer). {type} defines the type of the argument and is one of N, FASTN, LEASTN, PTR, MAX, where N corresponds to the number of bits in the argument.

The <inttypes.h> header shall define the following macro constants:
PRIxMAX printf specifier for intmax_t
PRIxN printf specifier for intN_t
PRIxLEASTN printf specifier for int_leastN_t
PRIxFASTN printf specifier for int_fastN_t
PRIxPTR printf specifier for intptr_t
SCNxMAX scanf specifier for intmax_t
SCNxN scanf specifier for intN_t
SCNxLEASTN scanf specifier for int_leastN_t
SCNxFASTN scanf specifier for int_fastN_t
SCNxPTR scanf specifier for intptr_t

Where:
•    x is one of d, i, o,u or x (for the printf specifiers this can also be an uppercase X). The specifier assumes the type to be signed for i and d, and unsigned for o, u, x and X.
•    N is 8, 16, 32, 64, or any other type width supported by the library in <cstdint>.

The <inttypes.h> header shall define the following functions:
imaxabs equivalent to abs for intmax_t
imaxdiv equivalent to div for intmax_t
strtoimax equivalent to strtol for intmax_t
strtoumax equivalent to strtoul for uintmax_t
wcstoimax equivalent to wcstol for intmax_t
wcstoumax equivalent to wcstoul for uintmax_t

The <inttypes.h> header shall define the following type:
imaxdiv_t Type returned by imaxdiv, which is the div_t equivalent for intmax_t



Related topics:
<float.h>   |   <iso646.h>   |   <limits.h>   |   <locale.h>   |   <math.h>   |   Standard Library in C

List of topics: C Programming

No comments:

Post a Comment