3 ms·
You overlook the %z printf specifier which attempts, but not quite solves the problem, because size_t comes in both a signed (ssize_t) and unsigned (size_t) var
by phkamp 15y ago
You overlook the %z printf specifier which attempts, but not quite solves the problem, because size_t comes in both a signed (ssize_t) and unsigned (size_t) variant.
I usually end up doing printf("%j", (intmax_t)foo);
- haberman 15y ago> because size_t comes in both a signed (ssize_t) and unsigned (size_t) variant. ssize_t is not ISO C. Also, %z is a modifier, not a specifier, so you can print size_t with %zu, or ssize_t with %zd.
- to3m 15y agoWon't "%zu" vs "%zd" do the trick? `z' is a modifier, like `l'. (That said, I've only ever used %zu myself... don't think I've ever used ssize_t. I'm pretty sure it's non-ISO.)
- caf 15y agoIt does (other variants like `%zx` are also fine).