tags:

views:

183

answers:

2

Hello,

gcc 4.1.2 c99

I have the following enum's in this file ccsmd.h :

enum options_e
{
    acm = 0,
    anm,
    smd,
    OPTIONS_LAST_ENTRY,

    OPTIONS_ENTRY_COUNT = OPTIONS_LAST_ENTRY
};

enum function_mode_e
{
    play = 0,
    record,
    bridge,
    MODE_LAST_ENTRY,

    MODE_ENTRY_COUNT = MODE_LAST_ENTRY
};

error: redeclaration of enumerator ‘LAST_ENTRY’
error: previous definition of ‘LAST_ENTRY’ was here
error: redeclaration of enumerator ‘ENTRY_COUNT’
error: previous definition of ‘ENTRY_COUNT’ was here

I have the LAST_ENTRY so that I can use that as the index of an array. So I like to keep it the same across all enums.

Many thanks for any advice,

A: 

Changed the prefixed the elements with the name of the enum.

robUK
This isn't an answer. And you realize that your edited question now makes no sense?
jamesdlin
I re-edited the question with the answer. And I posted the answer in this post. I don't really understand why you made that comment, its perfectly clear to me, and should be for anyone else. Maybe its just you.
robUK
But your edited question makes no sense (it refers to `LAST_ENTRY` and `ENTRY_COUNT` which no longer exist in your sample code), and without knowing what your question was, there's no easy way for other people to judge the answers to up/down-vote them. It's bad form. If you want to edit your question to include the answer, you shouldn't actually remove the original question.
jamesdlin
+1  A: 

Enumeration values exist in the same namespace as the enumeration is defined. That is, in regards to LAST_ENTRY, it's similar (used very loosely here) to:

enum options_e { /* ... */ );

// for the LAST_ENTRY value in options_e
static const int LAST_ENTRY = /* whatever */;

enum function_mode_e { /* ... */ );

// for the LAST_ENTRY value in function_mode_e
static const int LAST_ENTRY = /* whatever */;

As you can see, you're redefining LAST_ENTRY, hence the error. It's better to prefix your enum values with something to differentiate them:

enum options_e
{
    options_e_acm = 0,
    options_e_anm,
    options_e_smd,
    options_e_LAST_ENTRY,
    options_e_ENTRY_COUNT = options_e_LAST_ENTRY // note this is redundant 
};

enum function_mode_e
{
    function_mode_e_play = 0,
    function_mode_e_record,
    function_mode_e_bridge,
    function_mode_e_LAST_ENTRY,

    function_mode_e_ENTRY_COUNT = function_mode_e_LAST_ENTRY
};

Though now you lose whatever you were going for before. (Could you clarify what that was?)

GMan