本文介绍了printf warning:" format%08x expect format unsigned int ..."的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

....但我在printf中有一个unsigned long值。

当我使用gcc 4.x编译时出现了这个警告。

... 。

unsigned long offset = 0;

....


好​​吧,简单方式将取而代之的是


printf(在偏移%08x处找到eof,偏移);

做类似演员如

printf("'eof found at offset%08x",(unsigned int)offset);


很好,但这应该适用于像0xFFFFFFFF这样的值,这是

afaik最后可能的长值。 unsigned int只转到0xFFFF。


因此,如果我在进行试错法之前想一想,我认为它更好

忽略警告并跳过类型转换。

因为只是逻辑,它不能用于(unsigned int)类型转换为

整个ulong范围0x00000000..0xFFFFFFFF。 br />

-Andreas

.... but I have an unsigned long value in the printf.
This warning came when I used gcc 4.x to compile.
....
unsigned long offset = 0;
....

Well OK, an "easy" way would be instead of

printf ("eof found at offset %08x", offset);
to do a type cast like
printf ("eof found at offset %08x", (unsigned int) offset);

Fine, but is this supposed to work for values like 0xFFFFFFFF, which is
afaik the last possible long value. Unsigned int only goes to 0xFFFF.

So if I think before going the trial-and-error way, I conclude it''s better
to ignore the warning and skip the type cast.
Because just by logic, it cannot work with an (unsigned int) typecast for
the whole ulong range 0x00000000..0xFFFFFFFF.

-Andreas

推荐答案



" cast"

"cast"



" 08lx"应该做无条件的工作。


-

Ian Collins

"08lx" should do the job for unsigned long.

--
Ian Collins




[ ...]

[...]



" cast"


"cast"



[...]


我认为修正不清楚。 Ian的观点是,正确的

术语是强制转换,而不是强制转换。


-

Keith Thompson(The_Other_Keith)< http://www.ghoti.net/~ kst>

诺基亚

"我们必须做点什么。这是事情。因此,我们必须这样做。

- Antony Jay和Jonathan Lynn,是部长

[...]

I think that correction was unclear. Ian''s point is that the correct
term is "cast", not "type cast".

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"




" cast"


"cast"



" 08lx"应该做无条件的工作。

"08lx" should do the job for unsigned long.



谢谢,我又学到了一些东西。

我没有流血的想法,%x可以与小L一起_组合。


-Andreas

Thanks, I''ve learned something again.
I had no bleeding idea that the %x can be _combined_ with the small L.

-Andreas


这篇关于printf warning:&quot; format%08x expect format unsigned int ...&quot;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 06:48