-2

while coding in C, for the below syntax, I receive an error: expected an identifier, please let me know where am I going wrong ? Thank you.

enum a { 
    false;   // error : expected an identifier
    true;   // // error : expected an identifier
 };

typedef enum a a;
ameyCU
  • 16,489
  • 2
  • 26
  • 41
user3119673
  • 37
  • 1
  • 1

3 Answers3

3

Use comma after enum constant.

enum a { 
    false,
    true
};
artm
  • 17,291
  • 6
  • 38
  • 54
1

There should be a comma after false, not a semicolon.

And a comma after true is optional.

You don't even need to Google for it, just search this site. E.g. How to define an enumerated type (enum) in C?

Community
  • 1
  • 1
Mawg says reinstate Monica
  • 38,334
  • 103
  • 306
  • 551
  • Note that trailing comma in an enum is only optional since C99. Earlier, they weren't allowed. It was an inconsistency in the C language which was corrected with C99. – Lundin Dec 09 '15 at 13:28
1
typedef enum a { 
    false,
    true
} a;

is a succinct way of doing this. Note the comma after false, and the use of typedef.

I wouldn't recommend using false and true as enumerated names though; especially if you intend to port your code to C++.

Bathsheba
  • 231,907
  • 34
  • 361
  • 483