c - When do label declarations and label values make sense? -


the gnu c extensions provide specification of label declarations, labels can assigned variables can used gotos. while acknowledge goto makes sense in situations (e.g. substitute exception handling in higher languages), not understand how goto language extension justified. can provide concrete example, label values provide benefits?

the 1 time used effect threaded dispatch. imagine interpreter's inner loop:

while (1) {   switch ( *instruction_pointer ) {     case instr_a:       ...       break;     case instr_b:       ...       break;     ...   }   ++instruction_pointer; } 

the biggest performance problem looping construct there's one branch (ideally) in swtich statement handling instructions. branch can never predicted. threaded dispatch add explicit code every case go next:

void *instructions[] = { &&instr_a, &&instr_b, ... }; ...   goto *instructions[*instruction_pointer];    instr_a:     ...     goto *instructions[*++instruction_pointer];    instr_b:     ...     goto *instructions[*++instruction_pointer]; 

each instruction able jump directly start of next instruction. common sequences of instructions faster due cpu branch prediction. , guarantees jump table implementation, switch might not work out way if instruction space sparse.


Comments

Popular posts from this blog

php - Magento - Deleted Base url key -

javascript - Tooltipster plugin not firing jquery function when button or any click even occur -

java - WrongTypeOfReturnValue exception thrown when unit testing using mockito -