Reputation: 52498
Why do C enumeration constants need a name? Because this:
#include <stdio.h>
enum {NO, YES};
int main(void)
{
printf("%d\n", YES);
}
works just the same as this:
#include <stdio.h>
enum boolean {NO, YES};
int main(void)
{
printf("%d\n", YES);
}
Upvotes: 0
Views: 693
Reputation:
So that you can create variables of the enumeration type:
enum boolean read_file = NO;
Upvotes: 8
Reputation: 13972
If I'm understanding you right you're simply using an example that is too basic.
Days of the week is a good example of enums.
Upvotes: 2
Reputation:
If you want to create a type that is 'of the enum', such as:
enum boolean x;
x = NO;
The easier way to do this is with a typedef:
typedef enum {NO, YES} boolean;
And then all you have to do is use boolean as the type:
boolean x;
x = NO;
Upvotes: 6
Reputation: 100023
Well, you might want to define a function like this:
void here_is_my_answer(boolean v)
{
if (v == YES) {
} else {
{
}
Upvotes: 1