问题描述
我有一个非常简单的C code:
I have a very simple c code:
#include<stdio.h>
int main()
{
enum boolean{true,false};
boolean bl=false;
if(bl==false)
printf("This is the false value of boool\n");
boolean bl1=true;
if(bl1==true)
{
printf("This is the true value of boool\n");
}
return 0;
}
我只是想使用枚举类型的变量。但它给以下错误:
i was just trying to use enum type variable .but it is giving following error:
tryit4.c:5: error: ‘boolean’ undeclared (first use in this function)
tryit4.c:5: error: (Each undeclared identifier is reported only once
tryit4.c:5: error: for each function it appears in.)
tryit4.c:5: error: expected ‘;’ before ‘bl’
tryit4.c:6: error: ‘bl’ undeclared (first use in this function)
tryit4.c:8: error: expected ‘;’ before ‘bl1’
tryit4.c:9: error: ‘bl1’ undeclared (first use in this function)
我看不出有任何理由。能否请您解释可能是什么原因呢?
I don't see any reason for it. Can you please explain what could be the reason for it?
推荐答案
在声明枚举布尔{真,假}
,声明一个名为键入枚举布尔
。那该声明后继续使用,你将有名称:枚举布尔
,而不仅仅是布尔
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;
如果你愿意,你可以声明两个枚举布尔
输入和一个声明布尔别名p>
If you wish, you can declare both the enum boolean
type and the boolean
alias on one declaration
typedef enum boolean { true, false } boolean;
这篇关于误差枚举的声明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!