简体   繁体   中英

enum C, global variable error: variable has initializer but incomplete type

I used enum to have boolean variables in C using following code in header file:

enum myBool { FALSE = 0, TRUE = 1}; typedef enum _myBool Bool;

then I defined some global Bool variables with: extern Bool low;

then when I tried to initialize the variables to false in another .c file with Bool low = FALSE I get the error variable 'low' has initializer but incomplete type.

How can I fix this? Thanks so much!!

You have defined your enum as myBool not _myBool so you need to change

typedef enum _myBool Bool;

to

typedef enum myBool Bool;

then I defined some global Bool variables with: extern Bool low ;

so you have declared it in the another file. otherwise you will get linker error

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM