This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Warning C259: '=': different enumeration types

C51: V7.50

When I try to build the following code, I receive Warning C259, complaining about enumeration types :

typedef enum { ZERO, ONE, TWO } Numbers;

void main(void)
{
Numbers e_numbers;

e_numbers = (Numbers) ( ZERO |ONE |TWO );
}

  • ZERO | ONE | TWO produces the value 3 decimal, which is not a defined member of the enumeration. The warning message is obscure, but the compiler is trying to tell you that you are assigning a constant value not defined as part of your enumeration.

    One fix is

    typedef enum
        { ZERO, ONE, TWO, THREE }
        Numbers;
    

    Or, reconsider the assignment statement. Is it really a meaningful operation to OR members of this enum together?

  • "Is it really a meaningful operation to OR members of this enum together?"

    eg, are you confusing this with a Pascal set...?