Skip to content

Instantly share code, notes, and snippets.

@Diti
Created November 27, 2013 22:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Diti/7684035 to your computer and use it in GitHub Desktop.
Save Diti/7684035 to your computer and use it in GitHub Desktop.
Adding a `case` after the default one in a `switch` control structure still works. Compiled on a POSIX system with `gcc` and flags `-Wall -Wextra -pedantic -std=c89`.
#include <unistd.h>
void say(int x)
{
switch(x)
{
case 0:
write(1, "Case 0\n", 7);
break;
default:
write(1, "Case default\n", 13);
break;
case 1:
write(1, "Case 1\n", 7);
break;
}
}
int main(void)
{
say(0); /* Case 0 */
say(1); /* Case 1 */
say(-1); /* Case default */
return (0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment