inttypes.h(7POSIX)
๐ inttypes.h โ fixed size integer types ๐
okay bestie, welcome to inttypes.h, straight outta the POSIX Programmer's Manual โจ grab a snack, this one's a banger.
๐ซถ PROLOG ๐ซถ
so like, this manual page is part of the POSIX Programmer's Manual, periodt. but heads up โ the Linux implementation of this interface may differ (so pls consult the corresponding Linux manual page for the details of Linux behavior), or honestly the interface may just not be implemented on Linux at all. ๐ no cap.
โจ NAME โจ
inttypes.h โ fixed size integer types. that's it, that's the vibe. ๐
๐ธ SYNOPSIS ๐ธ
#include <inttypes.h>
๐ฆ DESCRIPTION ๐ฆ
okay so some of the functionality described on this reference page extends the ISO C standard. so if you want these symbols to even be visible in this header, your application shall define the appropriate feature test macro (check the System Interfaces volume of POSIX.1โ2017, Section 2.2, The Compilation Environment). it's giving โจfeature test macro eraโจ.
the <inttypes.h> header shall include the <stdint.h> header. it's a package deal bestie ๐
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.wchar_tโ as described in<stddef.h>.
then the 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. ๐
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. iconic ๐ฅ
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. (rare L but okay ๐)
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);
the following sections are informative. ๐ซ (so like, read them for the lore, not the law)
๐ 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 "\n", i);
return 0;
}
ate and left no crumbs ๐
๐ APPLICATION USAGE ๐
so the whole 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. 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. slay for portability fr fr ๐โจ
๐ 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. the way that 64 bits changed everythingโฆ main character energy honestly ๐
๐ฎ 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. so like, watch this space bestie ๐
๐ SEE ALSO ๐
<stddef.h>
The System Interfaces volume of POSIX.1โ2017, Section 2.2, The Compilation Environment, imaxabs(), imaxdiv(), strtoimax(), wcstoimax()
๐ COPYRIGHT ๐
okay legal girlie moment, gotta say it properly:
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!! this icon was brought to you by IEEE/The Open Group, 2017 โ the <rainbow>inttypes.h(7POSIX)</rainbow> girlies really said "portability is self care" and honestly? they were right. mwah ๐ go define your feature test macros, drink water, and stay consistent across platforms ๐ซถโจ
๐ฆ where this page comes from
- debian bookworm: manpages-posix-dev 2017a-2 ยท Other
- debian trixie: manpages-posix-dev 2017a-2 ยท Other
- ubuntu jammy: manpages-posix-dev 2017a-2 ยท Other
- ubuntu noble: manpages-posix-dev 2017a-2 ยท Other
- ubuntu resolute: manpages-posix-dev 2017a-2build1 ยท Other
- ubuntu stonking: manpages-posix-dev 2017a-2.1 ยท Other
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms