当我在条件中使用=时,如何让gcc警告我 [英] how to let gcc warn me when I use = in conditions

查看:95
本文介绍了当我在条件中使用=时,如何让gcc警告我的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




有时候,如果条件出错,我会写=而不是== in。

gcc编译器有什么方法可以给我一个警告吗?


祝福,



Hi,

Sometimes, I write = instead of == in if conditions by mistakes. Is
there any way the gcc compiler can give me a warning?

Best wishes,
Peng

推荐答案

Pe ******* @ gmail.com 在23/06/05写道:
Pe*******@gmail.com wrote on 23/06/05 :
有时候,如果条件出错,我会写=而不是==。是否有任何方式gcc编译器可以给我一个警告?
Sometimes, I write = instead of == in if conditions by mistakes. Is
there any way the gcc compiler can give me a warning?




-W -Wall。我还建议使用-O1或-O2进行数据流分析。


-

Emmanuel

C-FAQ: http://www.eskimo.com/~scs/C- faq / faq.html

C库: http://www.dinkumware.com/refxc.html


我曾经问过专家COBOL程序员,如何申报
声明COBOL中的局部变量,回复是:

什么是局部变量?



-W -Wall. I also recommend -O1 or -O2 for dataflow analysing.

--
Emmanuel
The C-FAQ: http://www.eskimo.com/~scs/C-faq/faq.html
The C-library: http://www.dinkumware.com/refxc.html

I once asked an expert COBOL programmer, how to
declare local variables in COBOL, the reply was:
"what is a local variable?"





Emmanuel Delahaye写道:


Emmanuel Delahaye wrote:
Pe ******* @ gmail.com 在23/06/05写道:
Pe*******@gmail.com wrote on 23/06/05 :
有时候,如果条件出错,我会写=而不是==。是否有任何方式gcc编译器可以给我一个警告?
Sometimes, I write = instead of == in if conditions by mistakes. Is
there any way the gcc compiler can give me a warning?



-W -Wall。我还建议使用-O1或-O2进行数据流分析。



-W -Wall. I also recommend -O1 or -O2 for dataflow analysing.




数据流分析是什么意思?谢谢!



What do you mean by "dataflow analysing"? Thanks!


" Pe ******* @ gmail.com"写道:
"Pe*******@gmail.com" wrote:

有时,如果条件出错,我会写=而不是==。
gcc编译器有什么方法可以给我一个警告吗?

Sometimes, I write = instead of == in if conditions by mistakes.
Is there any way the gcc compiler can give me a warning?




简单。养成先把常数放在一边的习惯。即:


int ch;


....

if(EOF == ch).. ..

如果你写= =代替==,
会大声抱怨。同样地:


while(EOF!=(ch = getc(fp))){

/ *用ch * /
}


-

"如果你想通过groups.google.com发布后续内容,请不要使用

破损的回复链接在文章的底部。点击

" show options"在文章的顶部,然后点击

回复在文章标题的底部。 - Keith Thompson



Simple. Get in the habit of putting the constant first. I.e:

int ch;

....
if (EOF == ch) ....

will complain loudly if you write = in place of ==. Similarly:

while (EOF != (ch = getc(fp))) {
/* do unspeakable things to and with ch */
}

--
"If you want to post a followup via groups.google.com, don''t use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers." - Keith Thompson


这篇关于当我在条件中使用=时,如何让gcc警告我的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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