Skip to content

Instantly share code, notes, and snippets.

@uucidl
Last active January 31, 2023 08:45
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 uucidl/cf8472fed08f02536f7ed9a162e7f0f1 to your computer and use it in GitHub Desktop.
Save uucidl/cf8472fed08f02536f7ed9a162e7f0f1 to your computer and use it in GitHub Desktop.
#define case(__x__) break; case __x__
#define fallthrough(__x__) case __x__
#define otherwise break; default
#include <assert.h>
#include <stdio.h>
int main(int argc, char **argv) {
switch(argc) {
case(0): printf("surprising\n");
case(1): printf("no argument given\n");
case(2): printf("a single argument given %s\n", argv[1]);
case(3): fallthrough(4): fallthrough(5): printf("between 2 and 4 arguments given\n");
otherwise: printf("over 4 arguments given\n");
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment