C 重新声明枚举数

C 重新声明枚举数,c,C,通用条款4.1.2 c99 我在此文件ccsmd.h中有以下枚举: enum options_e { acm = 0, anm, smd, LAST_ENTRY, ENTRY_COUNT = LAST_ENTRY }; enum function_mode_e { play = 0, record, bridge, LAST_ENTRY, ENTRY_COUNT = LAST_ENTRY }; 错误消息: e

通用条款4.1.2 c99

我在此文件ccsmd.h中有以下枚举:

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

    ENTRY_COUNT = LAST_ENTRY
};

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

    ENTRY_COUNT = 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

我有
LAST\u条目
,因此可以将其用作数组的索引。因此,我希望在所有枚举中都保持相同。

枚举值存在于定义枚举的同一命名空间中。也就是说,关于
最后一个\u条目
,它类似于(在这里非常松散地使用):

如您所见,您正在重新定义最后一个条目,因此出现了错误。最好在枚举值的前面加上区分它们的前缀:

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
};
虽然现在你失去了你以前想要的东西。(你能澄清那是什么吗?)

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
};