Add support for computed gotos
This is a GCC extension that allows C to use fast jump tables.
This commit is contained in:
committed by
greg-king5
parent
c2220f3c30
commit
3b3b16ee9c
55
test/val/computedgoto.c
Normal file
55
test/val/computedgoto.c
Normal file
@@ -0,0 +1,55 @@
|
||||
static unsigned char val, val2;
|
||||
|
||||
static void act(const unsigned char op) {
|
||||
|
||||
static const void * const arr[] = {
|
||||
&&op0,
|
||||
&&op1,
|
||||
&&op2,
|
||||
&&op3,
|
||||
&&op4,
|
||||
&&op5,
|
||||
&&op6,
|
||||
};
|
||||
|
||||
goto *arr[op];
|
||||
|
||||
op0:
|
||||
val += 1;
|
||||
return;
|
||||
|
||||
op1:
|
||||
val += 2;
|
||||
return;
|
||||
|
||||
op2:
|
||||
val += 3;
|
||||
return;
|
||||
|
||||
op3:
|
||||
val2 += 1;
|
||||
return;
|
||||
|
||||
op4:
|
||||
val2 += 5;
|
||||
return;
|
||||
|
||||
op5:
|
||||
val2 += 7;
|
||||
return;
|
||||
|
||||
op6:
|
||||
val2 += 9;
|
||||
return;
|
||||
}
|
||||
|
||||
int main() {
|
||||
|
||||
val = val2 = 0;
|
||||
|
||||
act(1);
|
||||
act(3);
|
||||
act(5);
|
||||
|
||||
return val == 2 && val2 == 8 ? 0 : 1;
|
||||
}
|
||||
Reference in New Issue
Block a user