Enumeration in switch statements

suggest change

A common use of enumerators is in switch statements, including state machines. If a switch on an enumeration has no default label and does not handle every enumerator, many compilers warn. GCC and Clang do so with -Wswitch.

enum State {
    start,
    middle,
    end
};

...

switch(myState) {
    case start:
       ...
    case middle:
       ...
} // warning: enumeration value 'end' not handled in switch [-Wswitch]

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents