I have some C++ code that prints a size_t
:
size_t a;
printf("%lu", a);
I'd like this to compile without warnings on both 32- and 64-bit architectures.
If this were C99, I could use printf("%z", a);
. But AFAICT %z
doesn't exist in any standard C++ dialect. So instead, I have to do
printf("%lu", (unsigned long) a);
which is really ugly.
If there's no facility for printing size_t
s built into the language, I wonder if it's possible to write a printf wrapper or somesuch such that will insert the appropriate casts on size_t
s so as to eliminate spurious compiler warnings while still maintaining the good ones.
Any ideas?
The printf
format specifier %zu
will work fine on C++ systems; there is no need to make it more complicated.