Asked in C Programming
C Programming

What do you mean by deadcode elimination?

Answer

User Avatar
Wiki User
05/05/2008

In compiler theory, dead code elimination is a compiler optimization used to reduce program size by removing code which does not affect the program. Dead code includes code that can never be executed (unreachable code), and code that only affects dead variables, that is variables that are irrelevant to the program. Consider the following example written in C. int foo() { int a = 24; int b = 25; /* Assignment to dead variable */ int c; c = a << 2; return c; b = 24; /* Unreachable code */ } The variable b is assigned a value after a return statement, which makes it impossible to get to. That is, since code execution is linear, and there is no conditional expression wrapping the return statement, any code after the return statement cannot possibly be executed. (This would not be the case if there were a label after the return statement, which opens the possibility of there being a jump that places execution after the return statement.)