Skip to content

Instantly share code, notes, and snippets.

@theonewolf
Last active December 16, 2015 19:38
Show Gist options
  • Select an option

  • Save theonewolf/5486167 to your computer and use it in GitHub Desktop.

Select an option

Save theonewolf/5486167 to your computer and use it in GitHub Desktop.
switch brain teaser
#include <stdio.h>
#include <stdlib.h>
enum option
{
OPT_ONE = 0x01,
OPT_TWO = 0x02,
OPT_THREE = 0x03,
OPT_FOUR = 0x04,
OPT_MAGIC = 0x05
};
void test_switch(enum option opt)
{
switch(opt)
{
OPT_ONE:
fprintf(stdout, "OPT_ONE\n");
break;
OPT_TWO:
fprintf(stdout, "OPT_TWO\n");
break;
OPT_THREE:
fprintf(stdout, "OPT_THREE\n");
break;
OPT_FOUR:
fprintf(stdout, "OPT_FOUR\n");
break;
OPT_MAGIC:
fprintf(stdout, "OPT_MAGIC\n");
break;
default:
fprintf(stdout, "default, no match found.\n");
};
}
int main(int argc, char* argv[])
{
test_switch(OPT_MAGIC);
return EXIT_SUCCESS;
}
@theonewolf
Copy link
Copy Markdown
Author

@ZeeD that's the reason why this was linked to as a "brain teaser" not a "compiler teaser." Although many brains are also good enough for this one it seems :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment