While researching how to do cross-platform printf()
format strings in C (that is, taking into account the number of bits I expect each integer argument to printf()
should be) I ran across this section of the Wikipedia article on printf()
. The article discusses non-standard options that can be passed to printf()
format strings, such as (what seems to be a Microsoft-specific extension):
printf("%I32d\n", my32bitInt);
It goes on to state that:
ISO C99 includes the inttypes.h header file that includes a number of macros for use in platform-independent printf coding.
... and then lists a set of macros that can be found in said header. Looking at the header file, to use them I would have to write:
printf("%"PRId32"\n", my32bitInt);
My question is: am I missing something? Is this really the standard C99 way to do it? If so, why? (Though I'm not surprised that I have never seen code that uses the format strings this way, since it seems so cumbersome...)