View Single Post
Old 2009-10-04, 12:13   #8
ldesnogu's Avatar
Jan 2008

10001110002 Posts

Originally Posted by jasonp View Post
If you include inttypes.h, you get macros to insert into format strings that will print 64-bit values correctly. On my mingw installation they are
inttypes.h:#define PRId64 "I64d"
inttypes.h:#define PRIi64 "I64i"
inttypes.h:#define PRIo64 "I64o"
inttypes.h:#define PRIu64 "I64u"
inttypes.h:#define PRIx64 "I64x"
inttypes.h:#define PRIX64 "I64X"
Admittedly it makes the format string painful to write, i.e.

printf("I have computed %" PRId64 "\n", answer);
It's ugly but it has another advantage on top of working on 32-bit Windows and Linux: it will do the correct thing when you go to a 64-bit platform where a 64-bit integer is defined as a long instead of a long long (%lu vs %llu).
ldesnogu is offline   Reply With Quote