Search code examples
cprintfsize-type

Can the intmax_t hold size_t?


Can the intmax_t hold size_t maximum decimal number? And what size type in printf have a biggest priority uintmax_t/intmax_t or size_t (ex. if i write printf("%zjd", x))?


Solution

  • Most likely not

    Both are implementation specific, so it's not really possible to answer.

    size_t is (usually) an unsigned integer holding the largest possible number of bits that will fit in a register on a given CPU. That's not exactly guaranteed in reality though, but I still haven't found an example where this isn't true.

    intmax_t is a signed integer, meaning it will probably have the bits required to store any value that a size_t can hold, but large values will not mean the same; the largest value that a size_t can hold, is likely going to be a negative integer when interpreted as an intmax_t.