EmanRuoy
EmanRuoy

Reputation: 87

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))?

Upvotes: 1

Views: 807

Answers (2)

Clearer
Clearer

Reputation: 2306

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.

Upvotes: 2

unwind
unwind

Reputation: 399949

  1. No, since size_t is unsigned that risks dropping one bit.
  2. I don't think you understand how printf() works, you can have "an optional length modifier" but not more than one.

Upvotes: 0

Related Questions