I thought those terms where synonymous, but a note in MISRA regarding dead code indicates this to be wrong? What's the difference? Is one a subset of the other?
In computer programming, unreachable code is part of the source code of a program which can never be executed because there exists no control flow path to the code from the rest of the program.
In some areas of computer programming, dead code is a section in the source code of a program which is executed but whose result is never used in any other computation. The execution of dead code wastes computation time and memory.
In Eclipse, "dead code" is code that will never be executed. Usually it's in a conditional branch that logically will never be entered. A trivial example would be the following: boolean x = true; if (x) { // do something } else { // this is dead code! }
Dead code - code that is executed but redundant, either the results were never used or adds nothing to the rest of the program. Wastes CPU performance.
function(){
// dead code since it's calculated but not saved or used anywhere
a + b;
}
Unreachable code - code that will never be reached regardless of logic flow. Difference is it's not executed.
function(){
return x;
// unreachable since returned
a = b + c;
}
Dead Code
Code that performs functions that have no effect. Basically stuff that wouldn't make a difference if removed.
Unreachable Code
Code that due to other logic will never be executed. This is usually the sign of an error.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With