Created
March 14, 2013 08:56
-
-
Save smirn0v/5159907 to your computer and use it in GitHub Desktop.
Designated initializers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "stdio.h" | |
int main() | |
{ | |
typedef enum { | |
white = 1, | |
red = 2, | |
green = 4, | |
blue = 8, | |
black = 16 | |
} Colour; // be sure to update array below! | |
char *enum_colours[] = { [white] = "white", [red] = "red", [green] = "green", | |
[blue] = "blue", [black] = "black" }; | |
Colour c = blue; | |
printf("The label for %d is %s\n", c, enum_colours[c]); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment