Topic : enum not providing warning C086

Forum : 8051

Original Post
Post Information Post
October 25, 2011 - 12:19pm

this is a follow on from the discussion at ...  I want to raise a warning when I try and assign a value to my typedef'd enum that is not in the enum, I have tried all the warning levels available (0,1,2) but none of them raise the warning. Additionally while the compiler raise a warning on the missed handling of an enum in a switch statement? typedef enum { actionEmpty = 0, actionOn, actionOff, actionRegulate, actionPulse } recipe_action; recipe_action my_enum_var; my_enum_var = 1234; //<----------WARNING SHOULD APPEAR HERE switch (my_enum_var) { case actionEmpty: break; case actionOn: break; case actionOff: break; //actionRegulate, <= case not handled <------ UNUSED ENUM SHOULD WE GET A WARNING? case actionPulse: break; } ie how do I make this warning appear. Warning C086 Assignment of integer to enumeration Initialization of an ‘enum’ variable with an integer type value. Assignment of an ‘enum’ variable with an integer type value. Thanks and Regards Marshall Brown

Post Information Post
October 26, 2011 - 10:06am
Raisonance Support Team

Hi Marshall,

Thanks for your report.
We have reproduced this in our labs. Indeed a warning should be a good thing.
I even think that assignment of a bare integer constant should raise a warning i.e., "my_enum_var = 1" should raise a warning. Possibly also arithmetic operations on enums such as "my_enum_var++" should raise a warning as well.

I will check with the R&D team what they can do about this.

Best Regards,