What uses do reading label address have?

Viewed 37

I wonder what can one use the var = &&label, i.e.: the reading of the address of a label for? I can only tell that by taking such address and then using it for jump doesn't require any __label__ mylabel; at beginning of the block (what's normally required to be able to jump to such label).

1 Answers

Taking the address of a label with && is a gcc extension. It allows you to use a variable containing a label address as a destination for goto. For example:

void *p = &&l0;
if (x==1) {
    p = &&l1;
} else if (x==2) {
    p = &&l2;
}
goto *p;

l0:
printf("at l0\n");
l1:
printf("at l1\n");
l2:
printf("at l2\n");

You can read more details of this feature in the gcc documentation.

Related