I think your least-bad available option is to borrow conceptually from <inttypes.h>
:
#ifdef _LP64
#define PRIdword "d"
#define PRIudword "u"
#else
#define PRIdword "ld"
#define PRIudword "lu"
#endif
and then
DWORD data;
printf("%"PRIdword, data);
This makes use of string constant concatenation, which all C90-compliant compilers should support. Note that the correct macro to test is _LP64
, not __x86_64__
; that way it will Just Work when you go to port to some other LP64 system, or to the shiny new "x32" mode of Linux/x86-64 (32-bit pointers, wide registers).
It might not be a bad idea to invest in a wholesale conversion to the <stdint.h>
types, but that won't get you out of this sort of thing, you'd just be writing
int32_t data;
printf("%"PRId32, data);
instead, and as far as I know most Windows compilers still don't have <inttypes.h>
, sigh.
In case you're wondering, the %
is not inside the macro so you can put format adjusters in if you want:
printf("%-32"PRIdword, data);