3 回答
![?](http://img1.sycdn.imooc.com/533e564d0001308602000200-100-100.jpg)
TA贡献1773条经验 获得超3个赞
这是我用于C ++代码的一组额外的偏执标志:
-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
那应该给你一些入门的知识。根据项目的不同,您可能需要将其调低以免看到来自第三方库的警告(通常对于免于警告的警告是很粗心的。)例如,Boost向量/矩阵代码会使g ++发出很多的噪音。
处理这种情况的一种更好的方法是在g ++周围编写包装程序,该包装程序仍然使用已调整到最大警告的警告,但允许禁止显示特定文件/行号的警告。我很久以前就写过这样的工具,一旦有时间清理它就会发布它。
![?](http://img1.sycdn.imooc.com/533e4d470001a00a02000200-100-100.jpg)
TA贡献1842条经验 获得超21个赞
我相信VC也支持
#pragma message ("note to self")
但是随着系统的发展和壮大,您需要每晚进行构建,同时有30位开发人员在工作,因此花数天时间才能阅读完所有笔记,甚至在阅读笔记并最终在无法跟上压力并不得不辞职的压力下休息...
确实没有,如果允许的话,警告的数量会迅速增加,并且您将无法发现真正重要的警告(未初始化的变量,此指针在构造函数中使用,...)。
这就是为什么我尝试将警告视为错误:大多数情况下,编译器正确地警告我,如果不是,我将其记录在代码中并添加前缀
#pragma warning ( push )
#pragma warning ( 4191 : disable )
// violent code, properly documented
#pragma warning ( pop )
我刚刚读到它们也有warning ( N : suppress )实用性。
- 3 回答
- 0 关注
- 1094 浏览
添加回答
举报