Search code examples
cpointersjump-table

jump table & code pointers


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?


Solution

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