inttypes.h(0P)
okay bestie, sit DOWN, we're doing the inttypes.h(0P) page π
this one's from the POSIX Programmer's Manual and it's honestly so iconic if you're the kind of girl who cares about whether her int is 16 bits on somebody else's machine. spoiler: she does. we all should. π«Ά
πΈ PROLOG πΈ
Real talk first: this manual page is part of the POSIX Programmer's Manual. The Linux implementation of this interface may differ β so like, consult the corresponding Linux manual page for the deets on Linux behavior. Or the interface may not be implemented on Linux at all. it's giving "check before you ship" π
π NAME π
inttypes.h β fixed size integer types β¨
yes that's it. that's the whole name. short. sweet. powerful. π
π¦ SYNOPSIS π¦
#include <inttypes.h>
that's the whole vibe. one include and you're in. π
β¨ DESCRIPTION β¨
Okay so some of the functionality described on this reference page extends the ISO C standard. Which means: applications shall define the appropriate feature test macro (see the System Interfaces volume of POSIX.1β2017, Section 2.2, The Compilation Environment) to enable the visibility of these symbols in this header. no macro, no symbols, no mercy. π
The <inttypes.h> header shall include the <stdint.h> header. bestie behavior. it brings its friend. π«Ά
The <inttypes.h> header shall define at least the following types:
imaxdiv_tβ structure type that is the type of the value returned by theimaxdiv()function. lowkey just a little struct wrapper, but she's important.wchar_tβ as described in<stddef.h>. borrowed from the neighbors, still valid.
π the macros (aka the whole point of this header) π
The <inttypes.h> header shall define the following macros. Each one 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. so basically: portable printf formats, finally. πβ¨
These macros have the general form of:
PRIβ character string literals for thefprintf()andfwprintf()family of functionsSCNβ character string literals for thefscanf()andfwscanf()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. see? the naming is not random, it's a whole system. iykyk. π
the fprintf() macros for signed integers
PRIdN PRIdLEASTN PRIdFASTN PRIdMAX PRIdPTR
PRIiN PRIiLEASTN PRIiFASTN PRIiMAX PRIiPTR
the fprintf() macros for unsigned integers
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
SCNdN SCNdLEASTN SCNdFASTN SCNdMAX SCNdPTR
SCNiN SCNiLEASTN SCNiFASTN SCNiMAX SCNiPTR
the fscanf() macros for unsigned integers
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 correspondingfprintf()andfwprintf()macros shall be defined and the correspondingfscanf()andfwscanf()macros shall be defined β unless the implementation does not have a suitable modifier for the type. that's the escape hatch. not every implementation can serve every look. π
π§ the functions π§
The following shall be declared as functions and may also be defined as macros. Function prototypes shall be provided. so you can call them, and you can also be surprised by them. standard behavior honestly. π
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);
The following sections are informative. β¨ (they're the bonus content, the behind-the-scenes, the director's commentary. we love them.)
π EXAMPLES π
okay this one is genuinely cute, look:
#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;
}
the comment is doing SO much heavy lifting and it's right to. uintmax_t always exists bestie. always. π«Ά
π APPLICATION USAGE π
The purpose of <inttypes.h> is to provide a set of integer types whose definitions are consistent across machines and independent of operating systems and other implementation idiosyncrasies. periodt.
It defines, through 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. which is the whole dream honestly. β¨
π RATIONALE π
storytime, bestie, because the lore here is real:
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. silent changes?? the audacity. not on my watch. π
The need for defining an extended integer type increased with the introduction of 64-bit systems. and that's the origin story of this entire header. ate.
π¦ FUTURE DIRECTIONS π¦
heads up: 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. so don't go naming your own stuff like that and then acting surprised. π
π SEE ALSO π
<stddef.h>- The System Interfaces volume of
POSIX.1β2017, Section 2.2, The Compilation Environment,imaxabs(),imaxdiv(),strtoimax(),wcstoimax()
π COPYRIGHT π
the legal bit, but make it respectful:
Portions of this text are reprinted and reproduced in electronic form from IEEE Std 1003.1-2017, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 7, 2018 Edition, Copyright (C) 2018 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 .
Any typographical or formatting errors that appear in this page are most likely to have been introduced during the conversion of the source files to man page format. To report such errors, see https://www.kernel.org/doc/man-pages/reporting_bugs.html .
and that's the whole page, bestie. every flag, every macro, every bit of lore β nothing dropped, nothing skipped, just delivered with the energy it deserved. π
this one came to you courtesy of IEEE/The Open Group, dated 2017, and it lives at inttypes.h(0P) β so next time you're yelling about PRIxMAX in a format string, you know exactly whose door to knock on. πβ¨ slay, stay portable, and always check your widths. π¦
π¦ where this page comes from
- alpine 3.22: man-pages-posix 2017a-r0 Β· custom
- alpine 3.23: man-pages-posix 2017a-r0 Β· custom
- alpine 3.24: man-pages-posix 2017a-r0 Β· custom
- arch rolling: man-pages 6.19-1
- arch rolling: man-pages 6.20-1 Β· BSD-2-Clause AND BSD-3-Clause AND BSD-4.3TAHOE AND BSD-4-Clause-UC AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-or-later AND GPL-3.0-or-later AND LGPL-3.0-linking-exception AND LGPL-3.0-or-later AND LicenseRef-Public-Domain AND LicenseRef-UltraPermissive AND Linux-man-pages-1-para AND Linux-man-pages-copyleft AND Linux-man-pages-copyleft-2-para AND Linux-man-pages-copyleft-var AND MIT AND Spencer-94
- nixpkgs unstable: man-pages-posix 2017a
- opensuse-leap 16.0: man-pages-posix 2017a-160000.4.1 Β· SUSE-IEEE
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms