Mantorok Redgormor wrote:
Is there any point ever in using enum with a tag to specify a variable
of that type instead of just creating the following:
enum { FOO, BOO };
I can access FOO and BOO in my program. So what is the point in ever
using something of the following:
enum woo { FOO, BOO };
enum woo bar;
Why would I ever use bar.FOO or bar.BOO when I can access FOO and BOO
anonymously?
Thank you for your post, Mantorok.
The following program seems impractical as a stand-alone program, but
perhaps it suggests some kind of embedded systems usage.
#include <stdio.h>
int main()
{
/*
* Idea for the following enum courtesy of _C Unleashed_,
* by Richard Heathfield, et al.
*/
enum State {
OFF, ON
};
enum State light;
enum State house_alarm;
int entered;
printf("Enter 1 to turn light on, 0 to turn light off: ");
scanf("%d", &entered);
switch (entered) {
case 0: {
light = OFF;
printf("Light is off\n");
break;
}
case ON:
light = ON;
printf("Light is on\n");
break;
}
default: printf("Input error\n");
}
printf("Enter 1 to turn house alarm on, 0 to turn house alarm off: ");
scanf("%d", &entered);
switch (entered) {
case 0: {
house_alarm = OFF;
printf("House alarm off\n");
break;
}
case 1: {
house_alarm = ON;
printf("House alarm on\n");
break;
}
default: printf("Input error\n");
}
return 0;
}
--Steve