Like the title says, for those who already know starting with GCC-6
you can catch a duplicate in an if
statement using this Flag -Wduplicated-cond
like this:
#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);
}
}
And the Output will be:
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){
~~^~~~
Now I know that the following:
else if( (a > 4) && (a < 6) )
is not the same like
else if( a == 5 )
but there happens that I do a check for the same condition if a == 5
.
My Question is, is there any chances to can catch (to avoid) this kind of duplicate?