最好的编译器警告级别的C / C ++编译器? [英] Best compiler warning level for C/C++ compilers?

查看:181
本文介绍了最好的编译器警告级别的C / C ++编译器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你推荐什么编译器警告级别不同的C / C ++编译器?

What compiler warning level do you recommend for different C/C++ compilers?

gcc和g ++会让你逃脱了很多的默认级别。我觉得对我来说最好的警告级别为-Wall。我总是尝试删除修复code为它生成的警告。 (即使有关使用括号逻辑precedence规则或说我真的是傻的人:如果(X = Y)')

gcc and g++ will let you get away with a lot on the default level. I find the best warning level for me is '-Wall'. And I always try to remove fix the code for the warnings it generates. (Even the silly ones about using parenthesis for logical precedence rules or to say I really mean 'if (x = y)')

什么是您最喜欢的级别不同的编译器,如Sun CC,ACC(HPUX),Visual Studio中,英特尔?

What are your favorite levels for the different compilers, such as Sun CC, aCC (HPUX ?), Visual Studio, intel?

编辑:

我只是想指出,我不使用-Werror(但我不知道这是实用程序)上的gcc / g ++的,因为我用的:

I just wanted to point out that I don't use "-Werror" (but I do understand it's utility) on gcc/g++ because, I use:


#warning "this is a note to myself"

在我的code的几个地方。是否所有的编译器明白指令#warning宏?

in a few places in my code. Do all the compilers understand the #warning macro?

推荐答案

这是一组我使用C ++ code额外偏执的标志:

This is a set of extra-paranoid flags I'm using for C++ code:

    -g -O -Wall -Weffc++ -pedantic  \
    -pedantic-errors -Wextra -Waggregate-return -Wcast-align \
    -Wcast-qual  -Wchar-subscripts  -Wcomment -Wconversion \
    -Wdisabled-optimization \
    -Werror -Wfloat-equal  -Wformat  -Wformat=2 \
    -Wformat-nonliteral -Wformat-security  \
    -Wformat-y2k \
    -Wimplicit  -Wimport  -Winit-self  -Winline \
    -Winvalid-pch   \
    -Wunsafe-loop-optimizations  -Wlong-long -Wmissing-braces \
    -Wmissing-field-initializers -Wmissing-format-attribute   \
    -Wmissing-include-dirs -Wmissing-noreturn \
    -Wpacked  -Wpadded -Wparentheses  -Wpointer-arith \
    -Wredundant-decls -Wreturn-type \
    -Wsequence-point  -Wshadow -Wsign-compare  -Wstack-protector \
    -Wstrict-aliasing -Wstrict-aliasing=2 -Wswitch  -Wswitch-default \
    -Wswitch-enum -Wtrigraphs  -Wuninitialized \
    -Wunknown-pragmas  -Wunreachable-code -Wunused \
    -Wunused-function  -Wunused-label  -Wunused-parameter \
    -Wunused-value  -Wunused-variable  -Wvariadic-macros \
    -Wvolatile-register-var  -Wwrite-strings

这应该给你的东西开始。根据一个项目,您可能需要调下来,以便看不到第三方库警告即将到来(这通常是pretty粗心的是没有警告的。)例如,升压矢量/矩阵code将G ++发出很大的噪音。

That should give you something to get started. Depending on a project, you might need to tone it down in order to not see warning coming from third-party libraries (which are usually pretty careless about being warning free.) For example, Boost vector/matrix code will make g++ emit a lot of noise.

有一个更好的方式来处理此类案件是写一个包装周围的g ++仍然使用调谐到最大警告,但允许一个人,从被视为特定的文件/行号坐席preSS他们。我这样一个工具,很久以前写的,并会释放一次我有时间把它清理干净。

A better way to handle such cases is to write a wrapper around g++ that still uses warnings tuned up to max but allows one to suppress them from being seen for specific files/line numbers. I wrote such a tool long time ago and will release it once I have time to clean it up.

这篇关于最好的编译器警告级别的C / C ++编译器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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