dla*_*lle 20 c gcc c99 gcc-warning
较新版本的gcc提供了Wimplicit-fallthrough,这对于大多数switch语句都很有用.但是,我有一个switch语句,我希望允许所有case语句的掉头.
有没有办法明确地通过?我宁愿避免Wno-implicit-fallthrough为这个文件编译.
编辑:我正在寻找一种方法来通过显式(如果可能)使下降,而不是通过编译器开关或编译指示关闭警告.
das*_*ght 18
使用 __attribute__ ((fallthrough))
switch (condition) {
case 1: __attribute__ ((fallthrough));
case 2: __attribute__ ((fallthrough));
case 3:
printf("1..3\n");
break;
}
Run Code Online (Sandbox Code Playgroud)
GCC fallghrough 魔术评论
如果你能帮助它,你不应该使用它,它很疯狂,但很高兴知道:
int main(int argc, char **argv) {
(void)argv;
switch (argc) {
case 0:
argc = 1;
// fall through
case 1:
argc = 2;
};
}
Run Code Online (Sandbox Code Playgroud)
通过以下方式防止 GCC 7.4.0 上的警告:
gcc -Wall -Wextra main.c
Run Code Online (Sandbox Code Playgroud)
man gcc 描述如何根据以下值识别或不识别不同的评论:
-Wimplicit-fallthrough=n
Run Code Online (Sandbox Code Playgroud)
C++17[[fallthrough]]属性
C++17 为此获得了标准化语法:GCC 7、-Wimplicit-fallthrough 警告,以及清除它们的可移植方式?