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 calledenum boolean. That the name you’ll have to use after that declaration:enum boolean, not justboolean.If you want a shorter name (like just
boolean), you’ll have to define it as an alias for the original full nameIf you wish, you can declare both the
enum booleantype and thebooleanalias on one declaration