return value
typedef enum{EVEN,ODD} oddeven_e;
oddeven_e is_odd_or_even(int num){
return num & 1 ? ODD : EVEN;
}
switch( is_odd_even(2021) ){ case ODD: ... break; case EVEN: ... break; default: fputs("WTF\n", stderr); break; }
Is this Better than boolean is even/is odd?
the boolean version if( FALSE == is_even(2021){ ... else{ ... }
Not try to use TRUE == ... you could end up in a black hole
This is a good design, not need a bool or error
Обсуждают сегодня