c – -Wall without -Wreturn-type
发布时间:2020-12-16 09:36:55 所属栏目:百科 来源:网络整理
导读:根据GCC手册,使用-Wall启用-Wreturn-type选项.但是,我无法找到一种正确的方法来禁用它,同时保持其余的-Wall启用. 考虑以下代码: func() {} 如果在没有警告的情况下编译,则不会生成输出.现在,如果我打开-Wall,将出现以下行: $gcc fn.c -Wallfn.c:1: warning
根据GCC手册,使用-Wall启用-Wreturn-type选项.但是,我无法找到一种正确的方法来禁用它,同时保持其余的-Wall启用.
考虑以下代码: func() {} 如果在没有警告的情况下编译,则不会生成输出.现在,如果我打开-Wall,将出现以下行: $gcc fn.c -Wall fn.c:1: warning: return type defaults to ‘int’ fn.c: In function ‘func’: fn.c:1: warning: control reaches end of non-void function 好的,一切都很好.现在,如果使用-Wreturn-type编译,则会生成相同的输出: $gcc fn.c -Wreturn-type fn.c:1: warning: return type defaults to ‘int’ fn.c: In function ‘func’: fn.c:1: warning: control reaches end of non-void function 因此,我得出结论,-Wreturn-type负责这些警告.但也许不是,或者我做的更糟糕,因为预计不会产生任何输出: $gcc fn.c -Wall -Wno-return-type fn.c:1: warning: return type defaults to ‘int’ 是否可以使用-Wall但完全禁用-Wreturn-type?或者也许我错过了另一个可用选项? 如果重要的话,我在Mac OS 10.7(Darwin 11)上使用GCC 4.2.1(奇怪的是,用LLVM编译:P) 解决方法
您可以使用-Wno-implicit-int来禁用该警告:
gcc -c -Wall -Wno-return-type -Wno-implicit-int fn.c 但是,这可能会导致您可能希望禁用其他警告.例如,它将禁止对如此声明的变量发出警告: static x = 1; 选择你的毒药. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |