Reputation: 9599
While compiling this code:
#include <stdio.h>
enum Boolean
{
TRUE,
FALSE
};
int main(int argc, char **argv)
{
printf("%d", Boolean.TRUE);
return 0;
}
I'm getting:
error: 'Boolean' undeclared (first use in this function)
What I'm doing wrong?
Upvotes: 3
Views: 2904
Reputation: 40145
#include <stdio.h>
enum Boolean { FALSE, TRUE };
struct {
const enum Boolean TRUE;
const enum Boolean FALSE;
} Boolean = { TRUE, FALSE };
int main(){
printf("%d\n", Boolean.TRUE);
return 0;
}
Upvotes: 1
Reputation: 162164
You're wrote Boolean.
Just write TRUE
or FALSE
without that prefix.
Upvotes: 0
Reputation: 372784
In C, you don't access individually enumerated constants using the syntax EnumType.SpecificEnum
. You just say SpecificEnum
. For example:
printf("%d", TRUE);
When you write
printf("%d", Boolean.TRUE);
C thinks that you're trying to go to the struct
or union
named Boolean
and access the TRUE
field, hence the compiler error.
Hope this helps!
Upvotes: 6