printf的格式说明uint32_t的类型和size_t [英] printf format specifiers for uint32_t and size_t
本文介绍了printf的格式说明uint32_t的类型和size_t的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
GCC 4.4.4 C89
-Wall -Wextra
gcc 4.4.4 c89 -Wall -Wextra
我有以下
size_t i = 0;
uint32_t k = 0;
printf("i [ %lu ] k [ %u ]\n", i, k);
在编译时,我得到以下警告:
I get the following warning when compiling:
format ‘%lu’ expects type ‘long unsigned int’, but argument has type ‘uint32_t’
当我跑这用夹板我得到了以下内容:
When I ran this using splint I got the following:
Format argument 1 to printf (%u) expects unsigned int gets size_t: k
非常感谢任何建议,
Many thanks for any advice,
史蒂夫
推荐答案
听起来像你期待为size_t
来是一样的无符号长
(可能64位)时,它实际上是一个 unsigned int类型
(32位)。尝试使用%祖
在这两种情况下。
Sounds like you're expecting size_t
to be the same as unsigned long
(possibly 64 bits) when it's actually an unsigned int
(32 bits). Try using %zu
in both cases.
我不能完全肯定,但。
这篇关于printf的格式说明uint32_t的类型和size_t的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文