Dead code

The term dead code has multiple definitions.

Uses your system voice; voice and rate in settings.

≈ 5 min read

Cite, export and learn8 citation formats · 8 exports · lesson and quiz

Names in other languages

No names in other languages are held for this entry yet.

Article bodies are English and are not machine-translated. A name in another language is not a translation of the article.

The term dead code has multiple definitions. Some use the term to refer to code (i.e. instructions in memory) which can never be executed at run-time.[1][2][3] 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.[4][5] The execution of dead code wastes computation time and memory.

While the result of a dead computation may never be used, it may raise exceptions or affect some global state, thus removal of such code may change the output of the program and introduce unintended bugs. Compiler optimizations are typically conservative in their approach to dead-code removal if there is any ambiguity as to whether removal of the dead code will affect the program output. The programmer may aid the compiler in this matter by making additional use of static and/or inline functions and enabling the use of link-time optimization.

Example

edit edit source int foo(int x, int y) { int z = x / y; return x * y; }

In the C code above example, although the division of x by y is computed and never used, it will raise a SIGFPE (floating point exception signal) when a division-by-zero occurs. Therefore, the removal of the dead code may change the output of the program.

Analysis

edit edit source

Dead-code elimination is a form of compiler optimization in which dead code is removed from a program. Dead code analysis can be performed using live-variable analysis, a form of static-code analysis and data-flow analysis. This is in contrast to unreachable code analysis which is based on control-flow analysis.

The dead-code elimination technique is in the same class of optimizations as unreachable code elimination and redundant code elimination.

In large programming projects, it is sometimes difficult to recognize and eliminate dead code, particularly when entire modules become dead. Test scaffolding can make it appear that the code is still live, and at times, contract language can require delivery of the code even when the code is no longer relevant.[6]

Some IDEs (such as Xcode, Visual Studio 2010[7] and Eclipse Galileo[8]) have the ability to locate dead code during the compiling stage.

While most optimization techniques seek to remove dead code in an implementation, in extreme forms of optimization for size it may sometimes be desirable to deliberately introduce and carefully shape seemingly dead code, when it allows to fold otherwise unrelated code sections together (and thereby reduce their combined size) so that the extra code will effectively not harm the first path of execution through the code but is used to carry out the actions necessary for the alternative paths of execution, for which other sections of the code may become dead code. On a more functional level, this can be seen as both, artificially introduction of harmless/useful side-effects and reduction of the redundancy of the code, but it can also be used down to opcode level in order to allow the usage of shorter instructions, which would not be possible when folding code sequences without the concerted introduction of side-effects caused by the dead code.

See also

edit edit source

References

edit edit source
  1. ^ "Hongwei Xi, Dead Code Elimination through Dependent Types" (PDF). Archived from the original (PDF) on 2012-03-10. Retrieved 2020-05-06. Wikipedia revision 1325383945, retrieved 2026-11-21
  2. ^ [1] Archived 2020-05-20 at the Wayback Machine DO-178B Wikipedia revision 1325383945, retrieved 2026-11-21
  3. ^ DO-178B Wikipedia/DO-178B. Wikipedia revision 1325383945, retrieved 2026-11-21
  4. ^ Debray, S. K., Evans, W., Muth, R., and De Sutter, B. 2000. Compiler techniques for code compaction. ACM Trans. Program. Lang. Syst. 22, 2 (Mar. 2000), 378–415. Wikipedia revision 1325383945, retrieved 2026-11-21
  5. ^ Appel, A. W. 1998 Modern Compiler Implementation in Java. Cambridge University Press. Wikipedia revision 1325383945, retrieved 2026-11-21
  6. ^ Douglas W. Jones Dead Code Maintenance, Risks 8.19 (Feb. 1, 1989) Archived 2011-07-08 at the Wayback Machine Wikipedia revision 1325383945, retrieved 2026-11-21
  7. ^ Habib Heydarian, Microsoft Corp Wikipedia revision 1325383945, retrieved 2026-11-21
  8. ^ Eclipse Developer Guide Wikipedia revision 1325383945, retrieved 2026-11-21
edit edit source

Text derived from https://en.wikipedia.org/w/index.php?oldid=1325383945 under CC BY-SA 4.0; modifications have been made.

Words in each sectionAnalysisAnalysisAnalysis: 308 words308ExampleExampleExample: 61 words61See alsoSee alsoSee also: 26 words26
Words in each section. Measured from the stored article body; sections below the minimum are not plotted.

Provenance

snapshot enwiki-001325383945 · captured 2025-12-02 · ledger · version history

Cite this page as: encyclopegia.org, “Dead code”, snapshot enwiki-001325383945. https://encyclopegia.org/a/dead-code