Advertisement
teknoraver

goto array

Feb 26th, 2016
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.36 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int main(int argc, char *argv[])
  5. {
  6.     void *jmp[] = { &&label0, &&label1, &&label2 };
  7.  
  8.     if(argc > 1) {
  9.         unsigned lbl = atoi(argv[1]);
  10.         if(lbl < 3)
  11.             goto *jmp[lbl];
  12.     }
  13.  
  14.     puts("none");
  15.     return 0;
  16.  
  17. label0:
  18.     puts("zero");
  19.     return 0;
  20.  
  21. label1:
  22.     puts("one");
  23.     return 0;
  24.  
  25. label2:
  26.     puts("two");
  27.     return 0;
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement