typedef enum {my_false, my_true = 5, my_maybe = 3} my_bool;
my_bool f(){return 2;}
int g(){return my_true;}
int main (){
my_bool mb = f();
int i = f();
printf("%d--%d\n", mb==i, mb);
mb = g();
i = g();
printf("%d--%d\n", mb==i, mb);
return 0;
}
What is happening when a function returns enum?
As I see it, in my code, f() can return any number, even if it's not defined inside the my_bool enum, but it seems that no matter what I return (like 2 in my example, the value stored inside my_bool mb = f(); would 1 unless I return 0ormy_false.
Is this what should happen? does
enumdecays immediately tointand thus has no problem with numbers that aren't defined in it?Why gcc generates warning:
comparison between signed and unsigned integer expressions [-Wsign-compare]... printf("%d--%d\n", mb==i, mb);? isn'tenumasigned int?- why defining the same value with different identifiers ok? (i.e.
typedef enum {xx = 1, yy = 1} zz;)