1

My code looks like this: (n is a number among 0,1,2 and 3, and loc_A/B/C/D each represents a block of code)

int test(int n){
    static void *jt[7]= {&&loc_A, &&loc_B, &&loc_C, &&loc_D};
    goto *jt[n];
  loc_A:
    ......
  loc_B:
    ......
  loc_C:
    ......
  loc_D:
    ......
}

What does "&&loc_A" stands for? Is it the address(or location) of the codes which loc_A represents?

Allen
  • 47
  • 7
  • why you want to use jump you can do it without jump.(that is better) I should add that this could help you http://stackoverflow.com/questions/15702297/dynamic-jump-to-label-in-c – Sina R. Jul 07 '13 at 04:06
  • 1
    You could do this very same thing using a switch statement. –  Jul 07 '13 at 04:15
  • @imsiso: thank you but actually I was learning the assembly representation of switch statement...and the original c codes are translated to the extended-C form above in order to illustrate the "jump-table". – Allen Jul 07 '13 at 04:21
  • @H2CO3: You're right the codes above are actually translated from a switch statement. – Allen Jul 07 '13 at 04:22

1 Answers1

1

Yes, but it's not standard C. Instead, it's a GNU language extension. Therefore, best avoided.

Oliver Charlesworth
  • 267,707
  • 33
  • 569
  • 680
  • Thanks. Does this "&&" have anything to do with "&" in C? Like the pointer of a pointer or something like that? Or it is created only to stand for a code location. – Allen Jul 07 '13 at 04:17
  • @Allen: I guess the GNU guys needed to choose a symbol, so they chose one that kind-of alluded to the idea of "address". – Oliver Charlesworth Jul 07 '13 at 04:19