问题
I have reviewed this but the accepted answer doesn't make sense to me. I should be able to define an enum in C99 as
enum WeekDays
{
MON, TUES, WED, THURS, FRI, SAT, SUN
}days;
and utilize the enum as follows in main as
days = FRI;
if (days == FRI)
{
printf("Thank God it's Friday!");
}
Why the additional work in the accepted answer to utilize the enum?
回答1:
Your code should work. In general though the accepted answer you point to is better programming practice. It's desirable to separate the declaration of new types from the use of those types. For example if you wrote a library for day manipulation, you might include the enum weekdays in that library. But that would be a bad place to define a variable for your program to use. Over time programmers have found this sort of separation valuable. It generally helps code be more readable
来源:https://stackoverflow.com/questions/46353655/c99-enum-need-clarification