这个警告意味着什么? [英] what does this warning mean ?

查看:96
本文介绍了这个警告意味着什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个警告是什么意思?

#include< stdio.h>


int main()

{

长l = 100;


printf(l is%li\ n,l * 10L);

返回0;

}

当我使用lcc-win32编译此程序时打印


lcc - A -anic -O long.c -o long.obj

警告c:\ tmp\long.c:4''main'的旧式函数定义'

警告c:\ tmp \ long.c:4缺少原型''main''

警告c:\ tmp \ long.c:4''int main( )''是非ANSI定义

警告c:\ tmp \ long.c:7格式i的printf参数不匹配。

预期long int得到int

0错误,4个警告

警告1-3:如何为main提供原型?


警告4:我给了它很长,但它说它得到了int。甚至

''(长)l * 10L''给出相同的警告。如何正确投射?

可以安全忽略???


gcc不打印任何警告。


-

mfg,heinrich :)

解决方案

Heinrich Pumpernickel说:
< blockquote class =post_quotes>
这个警告是什么意思?


#include< stdio.h>


int main()

{

long l = 100;


printf(" l is%li\\\
", l * 10L);


返回0;

}


当我用lcc-win32编译这个程序时它打印


lcc -A -ansic -O long.c -o long.obj

警告c:\ tmp \ long.c:4 ''main'的旧式函数定义

警告c:\ tmp \ long.c:4缺少''main'的原型'

警告c :\ tmp \ long.c:4''int main()''是非ANSI定义

警告c:\ tmp \ long.c:7格式i的printf参数不匹配。

预期long int得到int

0错误,4个警告


警告1-3:如何给主要原型?



将int main()更改为int main(void)


>

警告4:我给了它很长的int但它说它得到了int。甚至

''(长)l * 10L''给出相同的警告。



获得许可,可以为任何他们喜欢的原因生成诊断消息。大多数情况下,实现者非常擅长不发出虚假消息,但有时会显示偶尔的duff消息。

就是这种情况。


通常的算术转换要求如果任一操作数具有类型

long int,则另一个操作数转换为long int,这是双倍的

这里是真的,所以我们肯定有很长的*很长,这肯定会导致

a长,因为目的是产生一个普通类型,这也是

类型的结果 (两个引用都来自C89的3.2.1.5)。


所以代码是正确的。实现'生成诊断

消息并非不符合(因为只要正确的代码可以正常实现,就可以实现
生成诊断中的任何旧垃圾)

正确 - 我认为它确实如此?),但它确实表现出低QoI,并且

它让你想知道还有多少其他虚假诊断你的

实现正在生成。


如何正确投射?



请不要。毫无意义。该值已经具有正确的类型。

Casting无济于事。


可以安全地忽略???



代码是合法的C.使用对法律C提供误导性诊断的实现是否安全?这是一个判断呼叫,没有人(除了你的老板)可以为你做的事情。


gcc不打印任何警告。



啊,如果有的话我会给你一个很大的提示。


-

Richard Heathfield< http://www.cpax.org.uk>

电子邮件:-http:// www。 + rjh @

谷歌用户:< http://www.cpax.org.uk/prg/writings/googly.php>

Usenet是一个奇怪的放置" - dmr 1999年7月29日


Heinrich Pumpernickel< la **** @ linuxmail.orgwrites:


这个警告是什么意思?


#include< stdio.h>


int main()

{

长l = 100;


printf(l is%li\ n,l * 10L);


返回0;

}


当我用lcc-win32编译这个程序时打印


lcc -A -ansic -O long.c -o long.obj

警告c:\ tmp \ long.c:4''main''的旧式函数定义

警告c:\ tmp \ long.c:4缺少原型''main''

警告c:\ tmp \ long.c:4 ''int main()''是非ANSI定义

警告c:\ tmp \ long.c:7格式i的printf参数不匹配。

预计long int得到int

0错误,4个警告


警告1-3:如何给主要原型?



使用''int main(void)''而不是''int main()''。


警告4:我给了它很长的int但它说它得到了int。甚至

''(长)l * 10L''给出相同的警告。如何正确投射?

可以安全忽略???


gcc不打印任何警告。



我不知道。您是否复制并粘贴了确切的代码和错误

消息?如果没有,检查转录错误,例如数字1''

对比字母''l''。


这可能是lcc中的错误-win32。将详细信息发布到

comp.compilers.lcc,或使用任何可用的支持渠道。


-

Keith Thompson (The_Other_Keith) ks***@mib.org < http://www.ghoti.net/~kst>

圣地亚哥超级计算机中心< *< http://users.sdsc.edu/~kst>

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

- Antony Jay和Jonathan Lynn,是部长


Keith Thompson说:


Heinrich Pumpernickel< la **** @ linuxmail.orgwrites:



< snip> < br>


>警告4:我给了它long int但是它说它得到了int。甚至
''(长)l * 10L''给出同样的警告。如何正确地施放这个?
是否可以安全地忽略???



< snip>


这可能是lcc-win32中的错误。



他所说的没有任何建议。这完全是QoI

的问题。尽管代码正确且运行时行为正确,但无错误的符合实现可以合法地生成诊断消息。


-

Richard Heathfield< http://www.cpax.org.uk>

电子邮件:-http:// www。 + rjh @

谷歌用户:< http://www.cpax.org.uk/prg/writings/googly.php>

Usenet是一个奇怪的放置" - dmr 1999年7月29日


what does this warning mean ?
#include <stdio.h>

int main()
{
long l = 100;

printf("l is %li\n", l * 10L);

return 0;
}
when i compile this program with lcc-win32 it prints

lcc -A -ansic -O long.c -o long.obj
Warning c:\tmp\long.c: 4 old-style function definition for ''main''
Warning c:\tmp\long.c: 4 missing prototype for ''main''
Warning c:\tmp\long.c: 4 ''int main()'' is a non-ANSI definition
Warning c:\tmp\long.c: 7 printf argument mismatch for format i.
Expected long int got int
0 errors, 4 warnings
warning 1-3: how to give prototype for main ?

warning 4: i gave it long int but it says it got int . even
''(long)l * 10L'' gives same warning . how to cast this properly ?
is it safe to ignore ???

gcc prints no warnings .

--
mfg, heinrich :)

解决方案

Heinrich Pumpernickel said:

what does this warning mean ?
#include <stdio.h>

int main()
{
long l = 100;

printf("l is %li\n", l * 10L);

return 0;
}
when i compile this program with lcc-win32 it prints

lcc -A -ansic -O long.c -o long.obj
Warning c:\tmp\long.c: 4 old-style function definition for ''main''
Warning c:\tmp\long.c: 4 missing prototype for ''main''
Warning c:\tmp\long.c: 4 ''int main()'' is a non-ANSI definition
Warning c:\tmp\long.c: 7 printf argument mismatch for format i.
Expected long int got int
0 errors, 4 warnings
warning 1-3: how to give prototype for main ?

change int main() to int main(void)

>
warning 4: i gave it long int but it says it got int . even
''(long)l * 10L'' gives same warning .

Implementations are given licence to produce diagnostic messages for any
reason they like. Mostly, implementors are very good at not giving out
spurious messages, but sometimes the occasional duff message is displayed.
This is one such case.

The "usual arithmetic conversions" require that "if either operand has type
long int, the other operand is converted to long int", which is doubly
true here, so we definitely have long * long, which definitely results in
a long because "The purpose is to yield a common type, which is also the
type of the result" (both citations are from 3.2.1.5 of C89).

So the code is right. The implementation''s production of a diagnostic
message is not non-conforming (because implementations are allowed to
produce any old rubbish in the diagnostics as long as correct code works
correctly - and I presume it does?), but it does demonstrate low QoI, and
it makes you wonder how many other spurious diagnostics your
implementation is producing.

how to cast this properly ?

Please don''t. There''s no point. The value already has the proper type.
Casting is not going to help.

is it safe to ignore ???

The code is legal C. Is it safe to use an implementation that gives
misleading diagnostics for legal C? That''s a judgement call that nobody
else (apart from perhaps your boss) can make for you.

gcc prints no warnings .

Ah, there''s a Great Big Hint for you if ever I saw one.

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999


Heinrich Pumpernickel <la****@linuxmail.orgwrites:

what does this warning mean ?
#include <stdio.h>

int main()
{
long l = 100;

printf("l is %li\n", l * 10L);

return 0;
}
when i compile this program with lcc-win32 it prints

lcc -A -ansic -O long.c -o long.obj
Warning c:\tmp\long.c: 4 old-style function definition for ''main''
Warning c:\tmp\long.c: 4 missing prototype for ''main''
Warning c:\tmp\long.c: 4 ''int main()'' is a non-ANSI definition
Warning c:\tmp\long.c: 7 printf argument mismatch for format i.
Expected long int got int
0 errors, 4 warnings
warning 1-3: how to give prototype for main ?

Use ''int main(void)'' rather than ''int main()''.

warning 4: i gave it long int but it says it got int . even
''(long)l * 10L'' gives same warning . how to cast this properly ?
is it safe to ignore ???

gcc prints no warnings .

I don''t know. Did you copy-and-paste the exact code and error
messages? If not, check for transcription errors, such as digit 1''
vs. letter ''l''.

It could be a bug in lcc-win32. Post the details to
comp.compilers.lcc, or use whatever support channels are available.

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


Keith Thompson said:

Heinrich Pumpernickel <la****@linuxmail.orgwrites:

<snip>

>warning 4: i gave it long int but it says it got int . even
''(long)l * 10L'' gives same warning . how to cast this properly ?
is it safe to ignore ???

<snip>

It could be a bug in lcc-win32.

Nothing he has said suggests anything of the sort. It is strictly a QoI
matter. A bug-free conforming implementation could legally produce that
diagnostic message, despite correct code and correct runtime behaviour.

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999


这篇关于这个警告意味着什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆