Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

enum and define

Name: Anonymous 2010-09-25 12:15

So tell me, /prog/rammers

In C, why use enum instead of just #define?

Name: Anonymous 2010-09-25 13:20

I use them for this:

[0][~]% cat enum.c
enum e_num
{
        ENUM_CASE_1,
        ENUM_CASE_2,
        ENUM_CASE_3,
        ENUM_CASE_4
};

void f()
{
        enum e_num e = ENUM_CASE_3;
        switch(e){
                case ENUM_CASE_1:
                case ENUM_CASE_2:
                case ENUM_CASE_3:
                        break;
        }
}

[0][~]% gcc -S -o /dev/null -Wall enum.c
enum.c: In function ‘f’:

enum.c:12:2: warning: enumeration value ‘ENUM_CASE_4’ not handled in switch


[0][~]%

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List