INTTYPES(3) BSD Library Functions Manual INTTYPES(3)NAME
inttypes -- standard fixed-size integer types
SYNOPSIS
#include <inttypes.h>
DESCRIPTION
The <inttypes.h> header describes a set of format specifier macros aimed to increase portability both within and across operating systems.
It includes the <stdint.h> header and extends it with additional facilities.
Each of the following macros expand to a character string literal containing the format specifier suitable for use within the format argument
of a formatted I/O function such as printf(3). Each macro contains an identifier (PRI or SCN), a conversion specifier, and a possible length
modifier.
The length modifier follows the integer types described in stdint(3):
int8_t uint8_t
int16_t uint16_t
int32_t uint32_t
int64_t uint64_t
int_least8_t uint_least8_t
int_least16_t uint_least16_t
int_least32_t uint_least32_t
int_least64_t uint_least64_t
int_fast8_t uint_fast8_t
int_fast16_t uint_fast16_t
int_fast32_t uint_fast32_t
int_fast64_t uint_fast64_t
intmax_t uintmax_t
intptr_t uintptr_t
The following format specifiers are defined for the fprintf(3) and fscanf(3) families, respectively:
PRI?8 SCN?8
PRI?16 SCN?16
PRI?32 SCN?32
PRI?64 SCN?64
PRI?LEAST8 SCN?LEAST8
PRI?LEAST16 SCN?LEAST16
PRI?LEAST32 SCN?LEAST32
PRI?LEAST64 SCN?LEAST64
PRI?FAST8 SCN?FAST8
PRI?FAST16 SCN?FAST16
PRI?FAST32 SCN?FAST32
PRI?FAST64 SCN?FAST64
PRI?MAX SCN?MAX
PRI?PTR SCN?PTR
The available conversion specifiers, ``?'' in above, are d and i for signed integers and o, u, x, and X for unsigned integers. The X is not
available for the fscanf(3) family. Without the length modifier these would correspond with %d, %i, %o, %u, %x, and %X, respectively.
EXAMPLES
The following example demonstrates typical usage:
uint64_t i = 123;
...
(void)printf("i = %"PRIu64"
", i);
SEE ALSO printf(3), scanf(3), stdint(3)STANDARDS
The <inttypes.h> header conforms to ISO/IEC 9899:1999 (``ISO C99'') and IEEE Std 1003.1-2001 (``POSIX.1'').
HISTORY
The <inttypes.h> header was first introduced in NetBSD 1.6.
BSD March 21, 2010 BSD
Check Out this Related Man Page
<inttypes.h>(P) POSIX Programmer's Manual <inttypes.h>(P)
NAME
inttypes.h - fixed size integer types
SYNOPSIS
#include <inttypes.h>
DESCRIPTION
Some of the functionality described on this reference page extends the ISO C standard. Applications shall define the appropriate feature
test macro (see the System Interfaces volume of IEEE Std 1003.1-2001, Section 2.2, The Compilation Environment) to enable the visibility of
these symbols in this header.
The <inttypes.h> header shall include the <stdint.h> header.
The <inttypes.h> header shall include a definition of at least the following type:
imaxdiv_t
Structure type that is the type of the value returned by the imaxdiv() function.
The following macros shall be defined. Each 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 macros have the general form of PRI (character string literals for the fprintf() and fwprintf() family of functions) or SCN
(character string literals for the fscanf() and fwscanf() family of functions), followed by the conversion specifier, followed by a name
corresponding to a similar type name in <stdint.h>. In these names, N represents the width of the type as described in <stdint.h>. For
example, PRIdFAST32 can be used in a format string to print the value of an integer of type int_fast32_t.
The fprintf() macros for signed integers are:
PRIdN PRIdLEASTN PRIdFASTN PRIdMAX PRIdPTR
PRIiN PRIiLEASTN PRIiFASTN PRIiMAX PRIiPTR
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
The fscanf() macros for signed integers are:
SCNdN SCNdLEASTN SCNdFASTN SCNdMAX SCNdPTR
SCNiN SCNiLEASTN SCNiFASTN SCNiMAX SCNiPTR
The fscanf() macros for unsigned integers are:
SCNoN SCNoLEASTN SCNoFASTN SCNoMAX SCNoPTR
SCNuN SCNuLEASTN SCNuFASTN SCNuMAX SCNuPTR
SCNxN SCNxLEASTN SCNxFASTN SCNxMAX SCNxPTR
For each type that the implementation provides in <stdint.h>, the corresponding fprintf() and fwprintf() macros shall be defined and the
corresponding fscanf() and fwscanf() macros shall be defined unless the implementation does not have a suitable modifier for the type.
The following shall be declared as functions and may also be defined as macros. Function prototypes shall be provided.
intmax_t imaxabs(intmax_t);
imaxdiv_t imaxdiv(intmax_t, intmax_t);
intmax_t strtoimax(const char *restrict, char **restrict, int);
uintmax_t strtoumax(const char *restrict, char **restrict, int);
intmax_t wcstoimax(const wchar_t *restrict, wchar_t **restrict, int);
uintmax_t wcstoumax(const wchar_t *restrict, wchar_t **restrict, int);
EXAMPLES
#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 "
", i);
return 0;
}
The following sections are informative.
APPLICATION USAGE
The purpose of <inttypes.h> is to provide a set of integer types whose definitions are consistent across machines and independent of oper-
ating systems and other implementation idiosyncrasies. It defines, via typedef, integer types of various sizes. Implementations are free
to typedef them as ISO C standard integer types or extensions that they support. Consistent use of this header will greatly increase the
portability of applications across platforms.
RATIONALE
The ISO/IEC 9899:1990 standard specified that the language should support four signed and unsigned integer data types- char, short, int,
and long- but placed very little requirement on their size other than that int and short be at least 16 bits and long be at least as long
as int and not smaller than 32 bits. For 16-bit systems, most implementations assigned 8, 16, 16, and 32 bits to char, short, int, and
long, respectively. For 32-bit systems, the common practice has been to assign 8, 16, 32, and 32 bits to these types. This difference in
int size can create some problems for users who migrate from one system to another which assigns different sizes to integer types, because
the ISO C standard integer promotion rule can produce silent changes unexpectedly. The need for defining an extended integer type increased
with the introduction of 64-bit systems.
FUTURE DIRECTIONS
Macro names beginning with PRI or SCN followed by any lowercase letter or 'X' may be added to the macros defined in the <inttypes.h>
header.
SEE ALSO
The System Interfaces volume of IEEE Std 1003.1-2001, imaxdiv()
COPYRIGHT
Portions of this text are reprinted and reproduced in electronic form from IEEE Std 1003.1, 2003 Edition, Standard for Information Technol-
ogy -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 6, Copyright (C) 2001-2003 by the Institute of
Electrical and Electronics Engineers, Inc and The Open Group. In the event of any discrepancy between this version and the original IEEE
and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. The original Standard can be obtained
online at http://www.opengroup.org/unix/online.html .
IEEE /The Open Group 2003 <inttypes.h>(P)