In my C code, I'm fprintfing a "%lu" and giving a uint32_t for the corresponding field.  But, when I compile with -Wall in GCC (ver. 4.2.4), I get the following warning:
writeresults.c:16: warning: format '%4lu' expects type 'long unsigned int', but argument 2 has type 
`uint32_t'
Aren't a uint32_t and long unsigned int the same thing on 32-bit architectures?  Can this warning be avoided without eliminating the -Wall compiler switch or using a typecast (and if so, how)?
Yes, I'm still using a 32-bit computer/arch/OS/compiler (too poor at the moment to afford new 64-bit HW). Thanks!
uint32_t on x86 Linux with GCC is just unsigned int. So use fprintf(stream, "%4u", ...) (unsigned int) or better yet, fprintf(stream, "%4" PRIu32, ...) (the inttypes.h printf-string specifier for uint32_t).
The latter will definitely eliminate the compiler warning / error, and, additionally, is cross-platform.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With