ABR
ABR

Reputation: 125

typedef of enum bool return error in the compilation

I want to define bool type (enum format)

typedef enum bool_enum {
    false, 
    true,
} bool;

But is returning the folowing error in the compilation

error: expected identifier before numeric constant
  false, 
error: expected ‘;’, identifier or ‘(’ before ‘_Bool’
 } bool;

What is wrong in the enum type definition?

Upvotes: 2

Views: 1323

Answers (1)

unwind
unwind

Reputation: 400139

You probably have <stdbool.h> included, which typically contains:

#define true   1
#define false  0

So your names are not good, they collide with standard headers (which of course also define the name bool itself).

Drop this, and just use <stdbool.h> would be my advice.

Upvotes: 3

Related Questions