Hacker News new | ask | show | jobs
by dmm 4653 days ago
Imagine you just called time(2) and got a time_t value. Something like:

    time_t asdf = time();
And now you want to use printf to print that value to the screen. You can cast to 'long long', which is guaranteed to be at at least 64 bits wide, and ensure no loss of precision occurs:

    printf("%lld", (long long)asdf);
That will work whether time_t is 32 bit or 64 bit.
1 comments

If they just added a macro to inttypes.h, you could use that for the format specifier. If you want to print a uint32_t, you just use PRIu32.
> you could use that for the format specifier.

And end up with even more horrible and less readable format strings.

So we should use unportable format strings or cast all the values to long long? Is that better?

I personally find inttypes format strings readable.