close

http://stackoverflow.com/questions/1909825/error-with-the-declaration-of-enum

 

When you declare enum boolean { true, false }, you declare a type called enum boolean. That the name you'll have to use after that declaration: enum boolean, not just boolean.

If you want a shorter name (like just boolean), you'll have to define it as an alias for the original full name

typedef enum boolean boolean; 

If you wish, you can declare both the enum boolean type and the boolean alias on one declaration

typedef enum boolean { true, false } boolean; 

--

 

In C, there are two (actually more, but i keep it at this) kind of namespaces: Ordinary identifiers, and tag identifiers. A struct, union or enum declaration introduces a tag identifier:

enum boolean { true, false }; 
enum boolean bl = false; 

The namespace from which the identifier is chosen is specified by the syntax around. Here, it is prepended by a enum. If you want to introduce an ordinary identifier, put it inside a typedef declaration

typedef enum { true, false } boolean; 
boolean bl
= false; 

Ordinary identifiers don't need special syntax. You may declare a tag and ordinary one too, if you like.

arrow
arrow
    全站熱搜
    創作者介紹
    創作者 阿肯 的頭像
    阿肯

    韌體開發筆記

    阿肯 發表在 痞客邦 留言(0) 人氣()