sw_enum.c (592B)
1 /* A switch on an enum-typed selector. enum constants lower to int comparisons; 2 * this checks the enum-as-selector path round-trips like a plain int switch. 3 * volatile defeats folding. The selector COLOR_GREEN selects the case 4 * returning 42. Exit code 42. */ 5 enum color { COLOR_RED, COLOR_GREEN, COLOR_BLUE }; 6 int sel(enum color c) { 7 switch (c) { 8 case COLOR_RED: 9 return 10; 10 case COLOR_GREEN: 11 return 42; 12 case COLOR_BLUE: 13 return 12; 14 default: 15 return 99; 16 } 17 } 18 int test_main(void) { 19 volatile int raw = COLOR_GREEN; 20 return sel((enum color)raw); 21 }