 RE: enum type mixed with another type
Andy Neil
"The && operator ... returns 1 if both its
operands compare unequal to zero, 0 otherwise."
That's the point - it takes arguments of type int, and
returns a result of type int
The code you showed is using your "bool" enum type; not
int - hence the compiler warns you,
"enumeration type mixed with another type"
The "other type" in this case is, of course, int.
You missed section A4.2 in K&R:
"Enumerations behave like integers, but it is common for a
compiler to issue a warning when an object of a particular
enumeration type is assigned something other than one of its
constants, or an expression of its type"
The way to get around such warnings is always to use an
appropriate explicit cast.
"code should now be safer with this convension"
Not really.
I don't think it makes any difference at all to the safety here, but
it does have the disadvantage that the compiler can no longer produce
symbolic debug information for the enum type.
For safety, I think the explicit cast is probably the way to go -
as it makes your intention fully clear.
|