avr_inttypes(3avr)
β¨ avr_inttypes(3avr) β¨
okay bestie, welcome to avr_inttypes(3avr) π«Ά this is the whole ~vibe~ of <inttypes.h> β the header that makes your printf and scanf calls portable instead of a guessing game. no cap, this one is a bop, let's go π
π NAME π
avr_inttypes β <inttypes.h>: Integer Type conversions β¨
π¦ SYNOPSIS π¦
π§ Far pointers for memory access > 64K
typedef int32_t int_farptr_t
typedef uint32_t uint_farptr_t
yes bestie, two whole types that can actually point past the 64K line π
π macros for printf and scanf format specifiers
πΈ okay so important: for C++, these are only included if__STDC_LIMIT_MACROSis defined before including<inttypes.h>. don't forget it, it's giving "forgot my keys" energy otherwise π
first up, the signed decimal (d) and signed integer (i) girlies β 8, 16, 32, and the PTR ones all living their best life:
#define PRId8 'd'
#define PRIdLEAST8 'd'
#define PRIdFAST8 'd'
#define PRIi8 'i'
#define PRIiLEAST8 'i'
#define PRIiFAST8 'i'
#define PRId16 'd'
#define PRIdLEAST16 'd'
#define PRIdFAST16 'd'
#define PRIi16 'i'
#define PRIiLEAST16 'i'
#define PRIiFAST16 'i'
#define PRId32 'ld'
#define PRIdLEAST32 'ld'
#define PRIdFAST32 'ld'
#define PRIi32 'li'
#define PRIiLEAST32 'li'
#define PRIiFAST32 'li'
#define PRIdPTR PRId16
#define PRIiPTR PRIi16
now the octal / unsigned / lowercase-hex / BIG-hex squad, 8-bit edition π (look at 'X' being all capital, main character behaviour fr):
#define PRIo8 'o'
#define PRIoLEAST8 'o'
#define PRIoFAST8 'o'
#define PRIu8 'u'
#define PRIuLEAST8 'u'
#define PRIuFAST8 'u'
#define PRIx8 'x'
#define PRIxLEAST8 'x'
#define PRIxFAST8 'x'
#define PRIX8 'X'
#define PRIXLEAST8 'X'
#define PRIXFAST8 'X'
same lineup but 16-bit, they grew up so fast π:
#define PRIo16 'o'
#define PRIoLEAST16 'o'
#define PRIoFAST16 'o'
#define PRIu16 'u'
#define PRIuLEAST16 'u'
#define PRIuFAST16 'u'
#define PRIx16 'x'
#define PRIxLEAST16 'x'
#define PRIxFAST16 'x'
#define PRIX16 'X'
#define PRIXLEAST16 'X'
#define PRIXFAST16 'X'
and 32-bit, where every single one gets that little l glow-up π
('lo', 'lu', 'lx', 'lX' β the l is doing heavy lifting here):
#define PRIo32 'lo'
#define PRIoLEAST32 'lo'
#define PRIoFAST32 'lo'
#define PRIu32 'lu'
#define PRIuLEAST32 'lu'
#define PRIuFAST32 'lu'
#define PRIx32 'lx'
#define PRIxLEAST32 'lx'
#define PRIxFAST32 'lx'
#define PRIX32 'lX'
#define PRIXLEAST32 'lX'
#define PRIXFAST32 'lX'
and the PTR ones, which just straight-up borrow the 16-bit definitions. iconic, honestly:
#define PRIoPTR PRIo16
#define PRIuPTR PRIu16
#define PRIxPTR PRIx16
#define PRIXPTR PRIX16
β¨ ok now we flip it β these are the scanf side, the ones that go into your variables instead of out of them. watch the hh on the 8-bit ones, that's the difference between "reads your byte" and "reads 4 bytes and eats your stack" π:
#define SCNd8 'hhd'
#define SCNdLEAST8 'hhd'
#define SCNdFAST8 'hhd'
#define SCNi8 'hhi'
#define SCNiLEAST8 'hhi'
#define SCNiFAST8 'hhi'
#define SCNd16 'd'
#define SCNdLEAST16 'd'
#define SCNdFAST16 'd'
#define SCNi16 'i'
#define SCNiLEAST16 'i'
#define SCNiFAST16 'i'
#define SCNd32 'ld'
#define SCNdLEAST32 'ld'
#define SCNdFAST32 'ld'
#define SCNi32 'li'
#define SCNiLEAST32 'li'
#define SCNiFAST32 'li'
#define SCNdPTR SCNd16
#define SCNiPTR SCNi16
the SCN octal/unsigned/hex besties, 8-bit, all rocking that hh:
#define SCNo8 'hho'
#define SCNoLEAST8 'hho'
#define SCNoFAST8 'hho'
#define SCNu8 'hhu'
#define SCNuLEAST8 'hhu'
#define SCNuFAST8 'hhu'
#define SCNx8 'hhx'
#define SCNxLEAST8 'hhx'
#define SCNxFAST8 'hhx'
16-bit, hh graduates to no prefix at all, so proud of them π₯Ή:
#define SCNo16 'o'
#define SCNoLEAST16 'o'
#define SCNoFAST16 'o'
#define SCNu16 'u'
#define SCNuLEAST16 'u'
#define SCNuFAST16 'u'
#define SCNx16 'x'
#define SCNxLEAST16 'x'
#define SCNxFAST16 'x'
32-bit, l prefix activated, slay:
#define SCNo32 'lo'
#define SCNoLEAST32 'lo'
#define SCNoFAST32 'lo'
#define SCNu32 'lu'
#define SCNuLEAST32 'lu'
#define SCNuFAST32 'lu'
#define SCNx32 'lx'
#define SCNxLEAST32 'lx'
#define SCNxFAST32 'lx'
and the SCN PTR trio closing us out, borrowing from 16 again:
#define SCNoPTR SCNo16
#define SCNuPTR SCNu16
#define SCNxPTR SCNx16
whew. breathe. that's all of them, no skips, no crumbs left behind π«Ά
π Detailed Description π
#include <inttypes.h>
okay so like, what even is this header. listen: it includes all the exact-width integer definitions from <stdint.h>, and then it extends them with extra facilities that the implementation provides. it's the remix album. the deluxe edition πΏ
currently, the extensions include two additional integer types that could hold a "far" pointer (i.e. a code pointer that can address more than 64 KB), plus standard names for all the printf and scanf formatting options that are supported by <stdio.h>: Standard IO facilities. and here's the tea β since the library does not support the full range of conversion specifiers from ISO 9899:1999, only the conversions that are actually implemented get listed here. no fake options, only real ones π§
the idea behind these conversion macros is that, for each of the types defined by <stdint.h>, a macro is supplied that portably lets you format an object of that type in printf() or scanf() operations. example:
#include <inttypes.h>
uint8_t smallval;
int32_t longval;
...
printf("The hexadecimal value of smallval is %" PRIx8
", the decimal value of longval is %" PRId32 ".\n",
smallval, longval);
see how %" PRIx8 and %" PRId32 just slot right in there? that's the whole trick, that's the moment β¨
(part 1 of 2 β don't go anywhere bestie, there's more π)
π Macro Definition Documentation π
okay bestie, this is the big one. this whole section is just AVR-LibC handing you little macros so you never have to hardcode a format specifier again, because hardcoding format specifiers is how you end up on the news. each macro here expands to a string literal (or to another macro, no drama) that you drop straight into your printf/scanf format string. πΈ
quick vibe check before you scroll: these are for theprintf/scanffamily, and they're the whole point β you writeprintf("x = %" PRId16 "\n", x);and let the macro do the thinking. don't be out here typing%dfor a 32-bit value, i'm begging. π
π the printf girlies
π
signed decimal β PRIdβ¦
PRId16β'd', the decimalprintfformat forint16_tPRId32β'ld', the decimalprintfformat forint32_tPRId8β'd', the decimalprintfformat forint8_tPRIdFAST16β'd', the decimalprintfformat forint_fast16_tPRIdFAST32β'ld', the decimalprintfformat forint_fast32_tPRIdFAST8β'd', the decimalprintfformat forint_fast8_tPRIdLEAST16β'd', the decimalprintfformat forint_least16_tPRIdLEAST32β'ld', the decimalprintfformat forint_least32_tPRIdLEAST8β'd', the decimalprintfformat forint_least8_tPRIdPTRβ expands toPRId16, the decimalprintfformat forintptr_tπ«Ά
β¨ signed integer β PRIiβ¦
PRIi16β'i', the integerprintfformat forint16_tPRIi32β'li', the integerprintfformat forint32_tPRIi8β'i', the integerprintfformat forint8_tPRIiFAST16β'i', the integerprintfformat forint_fast16_tPRIiFAST32β'li', the integerprintfformat forint_fast32_tPRIiFAST8β'i', the integerprintfformat forint_fast8_tPRIiLEAST16β'i', the integerprintfformat forint_least16_tPRIiLEAST32β'li', the integerprintfformat forint_least32_tPRIiLEAST8β'i', the integerprintfformat forint_least8_tPRIiPTRβ expands toPRIi16, the integerprintfformat forintptr_tπ
π§ octal β PRIoβ¦
PRIo16β'o', the octalprintfformat foruint16_tPRIo32β'lo', the octalprintfformat foruint32_tPRIo8β'o', the octalprintfformat foruint8_tPRIoFAST16β'o', the octalprintfformat foruint_fast16_tPRIoFAST32β'lo', the octalprintfformat foruint_fast32_tPRIoFAST8β'o', the octalprintfformat foruint_fast8_tPRIoLEAST16β'o', the octalprintfformat foruint_least16_tPRIoLEAST32β'lo', the octalprintfformat foruint_least32_tPRIoLEAST8β'o', the octalprintfformat foruint_least8_tPRIoPTRβ expands toPRIo16, the octalprintfformat foruintptr_tπ
π unsigned decimal β PRIuβ¦
PRIu16β'u', the decimalprintfformat foruint16_tPRIu32β'lu', the decimalprintfformat foruint32_tPRIu8β'u', the decimalprintfformat foruint8_tPRIuFAST16β'u', the decimalprintfformat foruint_fast16_tPRIuFAST32β'lu', the decimalprintfformat foruint_fast32_tPRIuFAST8β'u', the decimalprintfformat foruint_fast8_tPRIuLEAST16β'u', the decimalprintfformat foruint_least16_tPRIuLEAST32β'lu', the decimalprintfformat foruint_least32_tPRIuLEAST8β'u', the decimalprintfformat foruint_least8_tPRIuPTRβ expands toPRIu16, the decimalprintfformat foruintptr_tβ¨
π₯ hex, but make it uppercase β PRIXβ¦
PRIX16β'X', the uppercase hexadecimalprintfformat foruint16_tPRIX32β'lX', the uppercase hexadecimalprintfformat foruint32_tPRIX8β'X', the uppercase hexadecimalprintfformat foruint8_tPRIXFAST16β'X', the uppercase hexadecimalprintfformat foruint_fast16_tPRIXFAST32β'lX', the uppercase hexadecimalprintfformat foruint_fast32_tPRIXFAST8β'X', the uppercase hexadecimalprintfformat foruint_fast8_tPRIXLEAST16β'X', the uppercase hexadecimalprintfformat foruint_least16_tPRIXLEAST32β'lX', the uppercase hexadecimalprintfformat foruint_least32_tPRIXLEAST8β'X', the uppercase hexadecimalprintfformat foruint_least8_tPRIXPTRβ expands toPRIX16, the uppercase hexadecimalprintfformat foruintptr_tπ
π¦ hex, but lowercase and chill β PRIxβ¦
PRIx16β'x', the hexadecimalprintfformat foruint16_tPRIx32β'lx', the hexadecimalprintfformat foruint32_tPRIx8β'x', the hexadecimalprintfformat foruint8_tPRIxFAST16β'x', the hexadecimalprintfformat foruint_fast16_tPRIxFAST32β'lx', the hexadecimalprintfformat foruint_fast32_tPRIxFAST8β'x', the hexadecimalprintfformat foruint_fast8_tPRIxLEAST16β'x', the hexadecimalprintfformat foruint_least16_tPRIxLEAST32β'lx', the hexadecimalprintfformat foruint_least32_tPRIxLEAST8β'x', the hexadecimalprintfformat foruint_least8_tPRIxPTRβ expands toPRIx16, the hexadecimalprintfformat foruintptr_tπ
π the scanf squad
heads up bestie, theSCNβ¦ones lowkey have different values than thePRIβ¦ones for the 8-bit types (they use thehhlength modifier), so do not, i repeat do not, get cute and swap them. π
πΈ signed decimal β SCNdβ¦
SCNd16β'd', the decimalscanfformat forint16_tSCNd32β'ld', the decimalscanfformat forint32_tSCNd8β'hhd', the decimalscanfformat forint8_tSCNdFAST16β'd', the decimalscanfformat forint_fast16_tSCNdFAST32β'ld', the decimalscanfformat forint_fast32_tSCNdFAST8β'hhd', the decimalscanfformat forint_fast8_tSCNdLEAST16β'd', the decimalscanfformat forint_least16_tSCNdLEAST32β'ld', the decimalscanfformat forint_least32_tSCNdLEAST8β'hhd', the decimalscanfformat forint_least8_tSCNdPTRβ expands toSCNd16, the decimalscanfformat forintptr_tπ«Ά
β generic-integer β SCNiβ¦
SCNi16β'i', the generic-integerscanfformat forint16_tSCNi32β'li', the generic-integerscanfformat forint32_tSCNi8β'hhi', the generic-integerscanfformat forint8_tSCNiFAST16β'i', the generic-integerscanfformat forint_fast16_tSCNiFAST32β'li', the generic-integerscanfformat forint_fast32_tSCNiFAST8β'hhi', the generic-integerscanfformat forint_fast8_tSCNiLEAST16β'i', the generic-integerscanfformat forint_least16_tSCNiLEAST32β'li', the generic-integerscanfformat forint_least32_tSCNiLEAST8β'hhi', the generic-integerscanfformat forint_least8_tSCNiPTRβ expands toSCNi16, the generic-integerscanfformat forintptr_tπ
π§ octal β SCNoβ¦
SCNo16β'o', the octalscanfformat foruint16_tSCNo32β'lo', the octalscanfformat foruint32_tSCNo8β'hho', the octalscanfformat foruint8_tSCNoFAST16β'o', the octalscanfformat foruint_fast16_tSCNoFAST32β'lo', the octalscanfformat foruint_fast32_tSCNoFAST8β'hho', the octalscanfformat foruint_fast8_tSCNoLEAST16β'o', the octalscanfformat foruint_least16_tSCNoLEAST32β'lo', the octalscanfformat foruint_least32_tSCNoLEAST8β'hho', the octalscanfformat foruint_least8_tSCNoPTRβ expands toSCNo16, the octalscanfformat foruintptr_tπ
π unsigned decimal β SCNuβ¦
SCNu16β'u', the decimalscanfformat foruint16_tSCNu32β'lu', the decimalscanfformat foruint32_tSCNu8β'hhu', the decimalscanfformat foruint8_tSCNuFAST16β'u', the decimalscanfformat foruint_fast16_tSCNuFAST32β'lu', the decimalscanfformat foruint_fast32_tSCNuFAST8β'hhu', the decimalscanfformat foruint_fast8_tSCNuLEAST16β'u', the decimalscanfformat foruint_least16_tSCNuLEAST32β'lu', the decimalscanfformat foruint_least32_tSCNuLEAST8β'hhu', the decimalscanfformat foruint_least8_tSCNuPTRβ expands toSCNu16, the decimalscanfformat foruintptr_tβ¨
π₯ hexadecimal β SCNxβ¦
SCNx16β'x', the hexadecimalscanfformat foruint16_tSCNx32β'lx', the hexadecimalscanfformat foruint32_tSCNx8β'hhx', the hexadecimalscanfformat foruint8_tSCNxFAST16β'x', the hexadecimalscanfformat foruint_fast16_tSCNxFAST32β'lx', the hexadecimalscanfformat foruint_fast32_tSCNxFAST8β'hhx', the hexadecimalscanfformat foruint_fast8_tSCNxLEAST16β'x', the hexadecimalscanfformat foruint_least16_tSCNxLEAST32β'lx', the hexadecimalscanfformat foruint_least32_tSCNxLEAST8β'hhx', the hexadecimalscanfformat foruint_least8_tSCNxPTRβ expands toSCNx16, the hexadecimalscanfformat foruintptr_tπ
π«Ά Typedef Documentation π«Ά
just two of them, and they're both about pointers that are way bigger than a normal one. iconic behaviour, honestly. π
- ```c typedef int32_t int_farptr_t
a signed integer type that can hold a pointer > 64 KiB π₯
- ```c
typedef uint32_t uint_farptr_t
an unsigned integer type that can hold a pointer > 64 KiB β and btw, see also pgm_get_far_address() π
β¨ Author β¨
Generated automatically by Doxygen for AVR-LibC from the source code. (so like, nobody wrote this by hand, it's the robot's finest work, and we love that for it π€π)
and that's a wrap bestie π this whole page is from AVR-LibC, Version 2.2.1, and it's the avr_inttypes(3avr) page β that's the name you'd yell if you wanted to look it up again. now go forth and never hardcode a format specifier again, i'm so serious. π
β¨
π¦ where this page comes from
- ubuntu resolute: avr-libc 1:2.2.1-1build1 Β· BSD-3-Clause
- ubuntu stonking: avr-libc 1:2.2.1-1build1 Β· BSD-3-Clause
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms