Skip to content

Instantly share code, notes, and snippets.

@smirn0v
Created March 14, 2013 08:56
Show Gist options
  • Save smirn0v/5159907 to your computer and use it in GitHub Desktop.
Save smirn0v/5159907 to your computer and use it in GitHub Desktop.
Designated initializers
#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