When researching how to do cross-platform printf() format strings in C (that is, given the number of bits, I expect every integer argument to printf() should be) I came across this section of the Wikipedia article on printf() . The article discusses non-standard parameters that can be passed to printf() format strings, for example (which looks like an extension for Microsoft):
printf("%I32d\n", my32bitInt);
It is further indicated that:
ISO C99 includes an inttypes.h file header, which includes several macros for use in platform-independent printing encoding.
... and then lists the set of macros that can be found in the specified header. Looking at the header file to use them, I would have to write:
printf("%"PRId32"\n", my32bitInt);
My question is: did I miss something? Is this really the standard way to C99? If so, why? (Although I'm not surprised that I never saw code that uses format strings in this way, since it seems so cumbersome ...)
c types c99 printf format-specifiers
mpontillo Jul 26 '09 at 3:52 2009-07-26 03:52
source share