I'm reviewing a lot of code that looks like this
typedef enum {
OPTION1
OPTION2
} option_t
...
void a_function(option_t option){
if(option == OPTION1){
...
} else if(option == OPTION2){
...
} else {
// report an error!
// can we ever get here?
}
}
My question is, is the else clause that reports the error needed? It seems to me, that as option is of type option_t, an enum that only has 2 possibilities, it should not be possible for option to have any value except OPTION1 and OPTION2, so it should be impossible for the else clause to ever be executed.