Is it possible to store the address of a label in a variable and use goto to jump to it?

前端 未结 14 1621
执念已碎
执念已碎 2020-12-04 09:35

I know everyone hates gotos. In my code, for reasons I have considered and am comfortable with, they provide an effective solution (ie I\'m not looking for \"don\'t do that\

14条回答
  •  天涯浪人
    2020-12-04 10:13

    #include 
    
    int main(void) {
    
      void *fns[3] = {&&one, &&two, &&three};   
      char p;
    
      p = -1;
    
      goto start; end:   return 0;     
      start:   p++;   
      goto *fns[p];
      one:  printf("hello ");  
      goto start;  
      two:  printf("World. \n");  
      goto start;
      three:  goto end;
    }
    

提交回复
热议问题