Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Undeclared enum?

Tags:

c

enums

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?

like image 692
cdonts Avatar asked Jan 22 '26 00:01

cdonts


1 Answers

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!

like image 67
templatetypedef Avatar answered Jan 24 '26 16:01

templatetypedef