Search code examples
enumsscopecompiler-constructionvxworks

Create two enum with identical 0 values


I want to create two enums with identical 0 (default values), which looks like:

enum testone_e    {
    NOCHANGE = 0,
    DOONETHING,
    BLABLA
};

enum testtwo_e    {
    NOCHANGE = 0,
    DOANOTHERTJHING,
} ;

but the compiler complains about: "NOCHANGE" has already been declared in the current scope

why that, isn't that two different scopes (as the values are in different enums)..? How do I solve this best? This is with WindRiver's diab compiler


Solution

  • In C, all enumeration constants are ints in the global scope. (More accurately, in the scope of the enum itself, which is usually file scope.)

    So you can only define each name once.