I have a code base that is designed to compile without warnings and run without any glitches on several architectures, all x86 console modes: MSDOS, Windows 32, Windows 32 GUI mode, Linux 32 and Linux 64.
Prior to adding Linux 64 support, this was easy. Almost all data was declared as int or from typedefs for BYTE, WORD, and DWORD:
typedef unsigned char BYTE; typedef unsigned short WORD; typedef unsigned long DWORD;
After adding 64-bit gcc support, DWORD needed a little tweaking to stay as a 32-bit value, since it represented the stored data:
// to compile DWORDs as 32 bits on 64-bit machines:
And it worked well in all environments:
DWORD data; printf ("%lu", data);
However, gcc -Wall now complains about format conversion:
warning: format '%ld' expects argument of type 'long int', but argument 1 has type 'DWORD {aka unsigned int}' [-Wformat]
Due to the extensive formatting, this code does indeed contain thousands of lines of formatting output: I would prefer not to modify the formatter of a certain type. A similar question was answered using the z modifier :
printf ("%zu", data);
But this forces Turbo C on the MSDOS and Win32 consoles to do something odd: it shows the %zu conversion specification as output instead of converting something.
Is there a cleaner way to handle type volatility in a way related to printf grains and basic data types?