就像标题说的那样,对于那些已经知道从GCC-6开始的人来说,您可以使用下面的这个标志-Wduplicated-cond在if语句中捕获一个副本:
#include <stdio.h>
int main(void){
int a = 5;
if( a == 5){
printf("First condition is True, A = %d\n", a);
}else if( a == 5 ){
printf("Second condition is True, A = %d\n", a);
}
}产出如下:
program.c:8:17: warning: duplicated ‘if’ condition [-Wduplicated-cond]
}else if( a == 5 ){
~~^~~~
program.c:6:11: note: previously used here
if( a == 5){
~~^~~~现在我知道以下几点:
else if( (a > 4) && (a < 6) )
不一样
else if( a == 5 )
但是,如果a == 5的话,我会检查相同的条件。
我的问题是,有没有机会抓住(避免)这种重复?
发布于 2016-05-18 06:40:23
https://stackoverflow.com/questions/37283128
复制相似问题