gcc警告 [英] gcc warning
问题描述
sprintf(buffer,"%05s"," 42");
[警告]'0''标志用于'%s''printf格式
这有什么问题,比如为什么警告?
sprintf(buffer, "%05s", "42");
[Warning] `0'' flag used with `%s'' printf format
What''s wrong with this, like why the warning?
推荐答案
" pemo" <我们*********** @ gmail.com>在消息中写道
news:dh ********** @ news.ox.ac.uk ...
"pemo" <us***********@gmail.com> wrote in message
news:dh**********@news.ox.ac.uk...
sprintf(buffer,"% 05s"," 42";
[警告]'0''标志用'%s''printf格式
这有什么问题,喜欢为什么要警告?
sprintf(buffer, "%05s", "42");
[Warning] `0'' flag used with `%s'' printf format
What''s wrong with this, like why the warning?
因为它错了。现在去读一本书或帮助文件或其他东西
并了解为什么这是错误的。你不会长大成为一名程序员,因为这对于互联网Magic Fix-It人来说是抱怨(或抱怨)。
-
Mabden
Because it is wrong. Now go and read a book or a help file or something
and LEARN why this is wrong. You will not grow up to be a programmer by
whinging (or whining) on about this to the Internet Magic Fix-It people.
--
Mabden
pemo写道:
pemo wrote:
sprintf(buffer,"%05s"," 42);
[警告]`0''标志用'%s''printf格式
这有什么问题,比如为什么警告?
sprintf(buffer, "%05s", "42");
[Warning] `0'' flag used with `%s'' printf format
What''s wrong with this, like why the warning?
错误:0标志的效果未定义
表示%s转换。如果你用这种方式调用sprintf(),那么C标准会引起人们的反对并且拒绝对你的程序可能会做什么说任何事。
。 行为未定义。
为什么警告:留作练习。
-
Eric Sosman
es*****@acm-dot-org.inva lid
What''s wrong: The effect of the `0'' flag is not defined
for the "%s" conversion. If you call sprintf() this way,
the C Standard throws up its hands and refuses to say anything
about what your program might do. "The behavior is undefined."
Why the warning: Left as an exercise.
--
Eric Sosman
es*****@acm-dot-org.invalid
>>现在去读一本书或帮助文件或其他东西
我有,并继续我试图找到一个可能会引用这个问题的参考资料:如果有人已经知道
的原因,我也会学习这个当然只会告诉我。
我发现的一个参考建议这样做!!
sprintf(buff,"%s","%05s" );
sprintf(缓冲区,buff,42);
这只是隐藏问题[无论如何来自
课程的编译器。
我也尝试使用MS的cl和intel的icl编译器 - 没有
在他们的h上抱怨这个最高警告级别。
" Mabden" < mabden@sbc_global.net>在消息中写道
新闻:0A ***************** @ newssvr13.news.prodigy.co m ...
>>Now go and read a book or a help file or something
I have, and am continuing in my attempts to locate a reference that might
explain this: I would also LEARN if someone that already knows the ''why'' of
this would simply tell me of course.
One reference I have found suggests doing this!!
sprintf(buff, "%s", "%05s");
sprintf(buffer, buff, "42");
That''s just hiding the problem [what ever it is] from the compiler of
course.
I''ve also tried this using MS''s cl, and intel''s icl compilers - neither
complains about this on their highest warning levels.
"Mabden" <mabden@sbc_global.net> wrote in message
news:0A*****************@newssvr13.news.prodigy.co m...
pemo <我们*********** @ gmail.com>在消息中写道
新闻:dh ********** @ news.ox.ac.uk ...
"pemo" <us***********@gmail.com> wrote in message
news:dh**********@news.ox.ac.uk...
sprintf(buffer,"%05s"," ; 42;
[警告]'0''标志用'%s''printf格式
这有什么问题,比如为什么警告?
sprintf(buffer, "%05s", "42");
[Warning] `0'' flag used with `%s'' printf format
What''s wrong with this, like why the warning?
因为它错了。现在去读一本书或帮助文件或其他东西
并了解为什么这是错误的。你不会长大成为一名程序员,通过对互联网魔术修复人员抱怨(或抱怨)这一点。
-
Mabden
Because it is wrong. Now go and read a book or a help file or something
and LEARN why this is wrong. You will not grow up to be a programmer by
whinging (or whining) on about this to the Internet Magic Fix-It people.
--
Mabden
这篇关于gcc警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!