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_MACROS is 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 the printf/scanf family, and they're the whole point β€” you write printf("x = %" PRId16 "\n", x); and let the macro do the thinking. don't be out here typing %d for a 32-bit value, i'm begging. 😭

πŸ“ the printf girlies

πŸ’… signed decimal β€” PRId…

  • PRId16 β€” 'd', the decimal printf format for int16_t
  • PRId32 β€” 'ld', the decimal printf format for int32_t
  • PRId8 β€” 'd', the decimal printf format for int8_t
  • PRIdFAST16 β€” 'd', the decimal printf format for int_fast16_t
  • PRIdFAST32 β€” 'ld', the decimal printf format for int_fast32_t
  • PRIdFAST8 β€” 'd', the decimal printf format for int_fast8_t
  • PRIdLEAST16 β€” 'd', the decimal printf format for int_least16_t
  • PRIdLEAST32 β€” 'ld', the decimal printf format for int_least32_t
  • PRIdLEAST8 β€” 'd', the decimal printf format for int_least8_t
  • PRIdPTR β€” expands to PRId16, the decimal printf format for intptr_t 🫢

✨ signed integer β€” PRIi…

  • PRIi16 β€” 'i', the integer printf format for int16_t
  • PRIi32 β€” 'li', the integer printf format for int32_t
  • PRIi8 β€” 'i', the integer printf format for int8_t
  • PRIiFAST16 β€” 'i', the integer printf format for int_fast16_t
  • PRIiFAST32 β€” 'li', the integer printf format for int_fast32_t
  • PRIiFAST8 β€” 'i', the integer printf format for int_fast8_t
  • PRIiLEAST16 β€” 'i', the integer printf format for int_least16_t
  • PRIiLEAST32 β€” 'li', the integer printf format for int_least32_t
  • PRIiLEAST8 β€” 'i', the integer printf format for int_least8_t
  • PRIiPTR β€” expands to PRIi16, the integer printf format for intptr_t πŸ’œ

🧚 octal β€” PRIo…

  • PRIo16 β€” 'o', the octal printf format for uint16_t
  • PRIo32 β€” 'lo', the octal printf format for uint32_t
  • PRIo8 β€” 'o', the octal printf format for uint8_t
  • PRIoFAST16 β€” 'o', the octal printf format for uint_fast16_t
  • PRIoFAST32 β€” 'lo', the octal printf format for uint_fast32_t
  • PRIoFAST8 β€” 'o', the octal printf format for uint_fast8_t
  • PRIoLEAST16 β€” 'o', the octal printf format for uint_least16_t
  • PRIoLEAST32 β€” 'lo', the octal printf format for uint_least32_t
  • PRIoLEAST8 β€” 'o', the octal printf format for uint_least8_t
  • PRIoPTR β€” expands to PRIo16, the octal printf format for uintptr_t πŸ“

🌈 unsigned decimal β€” PRIu…

  • PRIu16 β€” 'u', the decimal printf format for uint16_t
  • PRIu32 β€” 'lu', the decimal printf format for uint32_t
  • PRIu8 β€” 'u', the decimal printf format for uint8_t
  • PRIuFAST16 β€” 'u', the decimal printf format for uint_fast16_t
  • PRIuFAST32 β€” 'lu', the decimal printf format for uint_fast32_t
  • PRIuFAST8 β€” 'u', the decimal printf format for uint_fast8_t
  • PRIuLEAST16 β€” 'u', the decimal printf format for uint_least16_t
  • PRIuLEAST32 β€” 'lu', the decimal printf format for uint_least32_t
  • PRIuLEAST8 β€” 'u', the decimal printf format for uint_least8_t
  • PRIuPTR β€” expands to PRIu16, the decimal printf format for uintptr_t ✨

πŸ”₯ hex, but make it uppercase β€” PRIX…

  • PRIX16 β€” 'X', the uppercase hexadecimal printf format for uint16_t
  • PRIX32 β€” 'lX', the uppercase hexadecimal printf format for uint32_t
  • PRIX8 β€” 'X', the uppercase hexadecimal printf format for uint8_t
  • PRIXFAST16 β€” 'X', the uppercase hexadecimal printf format for uint_fast16_t
  • PRIXFAST32 β€” 'lX', the uppercase hexadecimal printf format for uint_fast32_t
  • PRIXFAST8 β€” 'X', the uppercase hexadecimal printf format for uint_fast8_t
  • PRIXLEAST16 β€” 'X', the uppercase hexadecimal printf format for uint_least16_t
  • PRIXLEAST32 β€” 'lX', the uppercase hexadecimal printf format for uint_least32_t
  • PRIXLEAST8 β€” 'X', the uppercase hexadecimal printf format for uint_least8_t
  • PRIXPTR β€” expands to PRIX16, the uppercase hexadecimal printf format for uintptr_t πŸ‘‘

πŸ¦‹ hex, but lowercase and chill β€” PRIx…

  • PRIx16 β€” 'x', the hexadecimal printf format for uint16_t
  • PRIx32 β€” 'lx', the hexadecimal printf format for uint32_t
  • PRIx8 β€” 'x', the hexadecimal printf format for uint8_t
  • PRIxFAST16 β€” 'x', the hexadecimal printf format for uint_fast16_t
  • PRIxFAST32 β€” 'lx', the hexadecimal printf format for uint_fast32_t
  • PRIxFAST8 β€” 'x', the hexadecimal printf format for uint_fast8_t
  • PRIxLEAST16 β€” 'x', the hexadecimal printf format for uint_least16_t
  • PRIxLEAST32 β€” 'lx', the hexadecimal printf format for uint_least32_t
  • PRIxLEAST8 β€” 'x', the hexadecimal printf format for uint_least8_t
  • PRIxPTR β€” expands to PRIx16, the hexadecimal printf format for uintptr_t πŸ’–

πŸŽ€ the scanf squad

heads up bestie, the SCN… ones lowkey have different values than the PRI… ones for the 8-bit types (they use the hh length modifier), so do not, i repeat do not, get cute and swap them. πŸ’€

🌸 signed decimal β€” SCNd…

  • SCNd16 β€” 'd', the decimal scanf format for int16_t
  • SCNd32 β€” 'ld', the decimal scanf format for int32_t
  • SCNd8 β€” 'hhd', the decimal scanf format for int8_t
  • SCNdFAST16 β€” 'd', the decimal scanf format for int_fast16_t
  • SCNdFAST32 β€” 'ld', the decimal scanf format for int_fast32_t
  • SCNdFAST8 β€” 'hhd', the decimal scanf format for int_fast8_t
  • SCNdLEAST16 β€” 'd', the decimal scanf format for int_least16_t
  • SCNdLEAST32 β€” 'ld', the decimal scanf format for int_least32_t
  • SCNdLEAST8 β€” 'hhd', the decimal scanf format for int_least8_t
  • SCNdPTR β€” expands to SCNd16, the decimal scanf format for intptr_t 🫢

⭐ generic-integer β€” SCNi…

  • SCNi16 β€” 'i', the generic-integer scanf format for int16_t
  • SCNi32 β€” 'li', the generic-integer scanf format for int32_t
  • SCNi8 β€” 'hhi', the generic-integer scanf format for int8_t
  • SCNiFAST16 β€” 'i', the generic-integer scanf format for int_fast16_t
  • SCNiFAST32 β€” 'li', the generic-integer scanf format for int_fast32_t
  • SCNiFAST8 β€” 'hhi', the generic-integer scanf format for int_fast8_t
  • SCNiLEAST16 β€” 'i', the generic-integer scanf format for int_least16_t
  • SCNiLEAST32 β€” 'li', the generic-integer scanf format for int_least32_t
  • SCNiLEAST8 β€” 'hhi', the generic-integer scanf format for int_least8_t
  • SCNiPTR β€” expands to SCNi16, the generic-integer scanf format for intptr_t πŸ’œ

🧚 octal β€” SCNo…

  • SCNo16 β€” 'o', the octal scanf format for uint16_t
  • SCNo32 β€” 'lo', the octal scanf format for uint32_t
  • SCNo8 β€” 'hho', the octal scanf format for uint8_t
  • SCNoFAST16 β€” 'o', the octal scanf format for uint_fast16_t
  • SCNoFAST32 β€” 'lo', the octal scanf format for uint_fast32_t
  • SCNoFAST8 β€” 'hho', the octal scanf format for uint_fast8_t
  • SCNoLEAST16 β€” 'o', the octal scanf format for uint_least16_t
  • SCNoLEAST32 β€” 'lo', the octal scanf format for uint_least32_t
  • SCNoLEAST8 β€” 'hho', the octal scanf format for uint_least8_t
  • SCNoPTR β€” expands to SCNo16, the octal scanf format for uintptr_t πŸ“

🌈 unsigned decimal β€” SCNu…

  • SCNu16 β€” 'u', the decimal scanf format for uint16_t
  • SCNu32 β€” 'lu', the decimal scanf format for uint32_t
  • SCNu8 β€” 'hhu', the decimal scanf format for uint8_t
  • SCNuFAST16 β€” 'u', the decimal scanf format for uint_fast16_t
  • SCNuFAST32 β€” 'lu', the decimal scanf format for uint_fast32_t
  • SCNuFAST8 β€” 'hhu', the decimal scanf format for uint_fast8_t
  • SCNuLEAST16 β€” 'u', the decimal scanf format for uint_least16_t
  • SCNuLEAST32 β€” 'lu', the decimal scanf format for uint_least32_t
  • SCNuLEAST8 β€” 'hhu', the decimal scanf format for uint_least8_t
  • SCNuPTR β€” expands to SCNu16, the decimal scanf format for uintptr_t ✨

πŸ”₯ hexadecimal β€” SCNx…

  • SCNx16 β€” 'x', the hexadecimal scanf format for uint16_t
  • SCNx32 β€” 'lx', the hexadecimal scanf format for uint32_t
  • SCNx8 β€” 'hhx', the hexadecimal scanf format for uint8_t
  • SCNxFAST16 β€” 'x', the hexadecimal scanf format for uint_fast16_t
  • SCNxFAST32 β€” 'lx', the hexadecimal scanf format for uint_fast32_t
  • SCNxFAST8 β€” 'hhx', the hexadecimal scanf format for uint_fast8_t
  • SCNxLEAST16 β€” 'x', the hexadecimal scanf format for uint_least16_t
  • SCNxLEAST32 β€” 'lx', the hexadecimal scanf format for uint_least32_t
  • SCNxLEAST8 β€” 'hhx', the hexadecimal scanf format for uint_least8_t
  • SCNxPTR β€” expands to SCNx16, the hexadecimal scanf format for uintptr_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