World Library  
Flag as Inappropriate
Email this Article

Dead code

Article Id: WHEBN0000084473
Reproduction Date:

Title: Dead code  
Author: World Heritage Encyclopedia
Language: English
Subject: Compiler construction, Optimizing compiler, Software anomalies, Source code, Eager evaluation
Collection: Compiler Construction, Software Anomalies, Source Code
Publisher: World Heritage Encyclopedia

Dead code

In 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.[1][2] 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 1
  • Analysis 2
  • See also 3
  • References 4
  • External links 5


int foo (int iX, int iY)
        int iZ = iX/iY;

        return iX*iY;

In the above example, although the division of iX by iY is computed and never used, it will throw an exception when a division by zero occurs. Therefore the removal of the dead code may change the output of the program.


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.[3]

Some IDEs (such as Visual Studio 2010 [4] and Eclipse Galileo [5]) 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


  1. ^ 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.
  2. ^ Appel, A. W. 1998 Modern Compiler Implementation in Java. Cambridge University Press.
  3. ^ Douglas W. Jones Dead Code Maintenance, Risks 8.19 (Feb. 1, 1989)
  4. ^ Habib Heydarian, Microsoft Corp
  5. ^ Eclipse Developer Guide

External links

  • Dead Code Detector (DCD) simply finds never used code in your Java/JEE applications
  • Comparisons of some Java Dead Code Detector
  • UCDetector Eclipse PlugIn to find dead java code
This article was sourced from Creative Commons Attribution-ShareAlike License; additional terms may apply. World Heritage Encyclopedia content is assembled from numerous content providers, Open Access Publishing, and in compliance with The Fair Access to Science and Technology Research Act (FASTR), Wikimedia Foundation, Inc., Public Library of Science, The Encyclopedia of Life, Open Book Publishers (OBP), PubMed, U.S. National Library of Medicine, National Center for Biotechnology Information, U.S. National Library of Medicine, National Institutes of Health (NIH), U.S. Department of Health & Human Services, and, which sources content from all federal, state, local, tribal, and territorial government publication portals (.gov, .mil, .edu). Funding for and content contributors is made possible from the U.S. Congress, E-Government Act of 2002.
Crowd sourced content that is contributed to World Heritage Encyclopedia is peer reviewed and edited by our editorial staff to ensure quality scholarly research articles.
By using this site, you agree to the Terms of Use and Privacy Policy. World Heritage Encyclopedia™ is a registered trademark of the World Public Library Association, a non-profit organization.

Copyright © World Library Foundation. All rights reserved. eBooks from Project Gutenberg are sponsored by the World Library Foundation,
a 501c(4) Member's Support Non-Profit Organization, and is NOT affiliated with any governmental agency or department.