Skip to content

Instantly share code, notes, and snippets.

@ashelly
Last active August 29, 2015 14:05
Show Gist options
  • Save ashelly/6091bf05f4382cd30d9a to your computer and use it in GitHub Desktop.
Save ashelly/6091bf05f4382cd30d9a to your computer and use it in GitHub Desktop.
Method of easily selecting from multitude of exclusive compile time options.
//set only one of the following to 1.
#define OPTION_PRIMARY 1
#define OPTION_ALTERNATE 0
#define OPTION_UNLIKELY 0
//Did you follow the rules?
#if ((OPTION_PRIMARY+OPTION_ALTERNATE+OPTION_UNLIKELY)!=1)
#error("Error configuring options")
#endif
/*...*/
#if OPTION_PRIMARY
printf("primary");
#elif OPTION_SECONDARY
puts("secondary");
#elif OPTION_UNLIKELY
putc('U');
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment