简体   繁体   English

枚举C,全局变量错误:变量具有初始化程序,但类型不完整

[英]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: 我使用枚举在头文件中使用以下代码在C中具有布尔变量:

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

then I defined some global Bool variables with: extern Bool low; 然后我定义了一些全局的Bool变量: 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. 然后,当我尝试使用Bool low = FALSE在另一个.c文件中将变量初始化为false时,我得到了错误变量'low'具有初始化程序但类型不完整的错误。

How can I fix this? 我怎样才能解决这个问题? Thanks so much!! 非常感谢!!

You have defined your enum as myBool not _myBool so you need to change 您已将枚举定义为myBool而不是_myBool因此需要进行更改

typedef enum _myBool Bool;

to

typedef enum myBool Bool;

then I defined some global Bool variables with: extern Bool low ; 然后我定义了一些全局的Bool变量: extern Bool low ;

so you have declared it in the another file. 所以您已经在另一个文件中声明了它。 otherwise you will get linker error 否则会出现链接器错误

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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