关于printf()long unsigned int和uint32_t的编译器警告

pr1*_*268 5 c linux printf gcc

在我的C代码,我在fprintf荷兰国际集团一"%lu"和给予uint32_t的相应字段.但是,当我-Wall在GCC(版本4.2.4)中编译时,我收到以下警告:

writeresults.c:16: warning: format '%4lu' expects type 'long unsigned int', but argument 2 has type 
`uint32_t'
Run Code Online (Sandbox Code Playgroud)

是不是uint32_tlong unsigned int32位架构是一回事吗?在不消除-Wall编译器开关或使用类型转换(如果是,如何)的情况下,是否可以避免此警告?

是的,我仍在使用32位计算机/ arch/OS /编译器(目前太差,无法提供新的64位硬件).谢谢!

Con*_*yer 9

uint32_t在x86 Linux上使用GCC就是unsigned int.所以使用fprintf(stream, "%4u", ...)(unsigned int)或更好,fprintf(stream, "%4" PRIu32, ...)(inttypes.hprintf-string说明符uint32_t).

后者肯定会消除编译器警告/错误,此外,还是跨平台的.