Allen
Allen

Reputation: 47

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?

Upvotes: 1

Views: 310

Answers (1)

Oliver Charlesworth
Oliver Charlesworth

Reputation: 272537

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

Upvotes: 1

Related Questions