FACTOID # 117: In Germany and Italy, every second person owns a car.
 
 Home   Encyclopedia   Statistics   Countries A-Z   Flags   Maps   Education   Forum   FAQ   About 
 
WHAT'S NEW
RECENT ARTICLES
More Recent Articles »
 

FACTS & STATISTICS    Simple view

  1. Select countries to view: (hold down Control key and click to select several)

     

     

    Compare:

     

     

  1. Select fact or statistic: (* = graphable)

     

     

     

  2. (OPTIONAL) Compare to statistic: (both need to be graphable)

     

     

     

  3. View result as:

     

       
(OR) SEARCH ALL encyclopedia, stats & forums:   

Encyclopedia > Dead code elimination

Dead code elimination is a technique used in computer science to reduce program size by removing code which can never be executed.


Consider the following example written in C.

 void foo() { int a = 24; int b = 25; int c; c = a << 2; return; b = 24; } 

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.)


Furthermore, if we elimate that assignment, than we can see that the variable b is never used at all, except for its declaration and inital assignment. Depending on the aggressiveness of the optimizer, the variable b might be eliminated entirely from the generated code.


Also, even though some calculations are performed in the function, their values are not stored in locations accessible outside the scope of this function. Furthermore, the function does not return a value. Thus, it can be said that the function has no side effects and returns no value, and thus does no work. In that case, a highly aggressive optimizer might reduce this function to nothing more than a return call, or even eliminate it entirely.


Most advanced compilers have options to activate dead code elimination, sometimes at varying levels. A lower level might only remove instructions which cannot be executed. A higher level might also not reserve space for unused variables. Yet a higher level might determine instructions or functions that serve no purpose and eliminate them.


A common use of dead code elimination is as an alternative to optional code inclusion via a preprocessor. Consider the following code.

 int main() { int a = 5; int b = 6; int c; c = a * (b >> 1); if (0) { /* DEBUG */ printf("%d n", c); } return c; } 

Because the expression 0 will always evaluate to false, the code inside the if statement can never be executed, and dead code elimination would remove it entirely from the optimized program. This technique is common in debugging to optionally activate blocks of code; using an optimizer with dead code elimination eliminates the need for using a preprocessor to perform the same task.


  Results from FactBites:
 
Dead Code Elimination With the Link-Editor in the Solaris OS (734 words)
This process of concatenation may result in an output that includes one or more unused functions (dead code) and is larger than necessary.
Unused section elimination in the link-editor is enabled with the
Unless otherwise licensed, code in all technical manuals herein (including articles, FAQs, samples) is provided under this License.
Dead code elimination - definition of Dead code elimination in Encyclopedia (449 words)
Dead code elimination is a technique used in computer science to reduce program size by removing code which can never be executed.
A common use of dead code elimination is as an alternative to optional code inclusion via a preprocessor.
This technique is common in debugging to optionally activate blocks of code; using an optimizer with dead code elimination eliminates the need for using a preprocessor to perform the same task.
  More results at FactBites »


 

COMMENTARY     


Share your thoughts, questions and commentary here
Your name
Your comments
Please enter the 5-letter protection code

Want to know more?
Search encyclopedia, statistics and forums:

 


Lesson Plans | Student Area | Student FAQ | Reviews | Press Releases |  Feeds | Contact
The Wikipedia article included on this page is licensed under the GFDL.
Images may be subject to relevant owners' copyright.
All other elements are (c) copyright NationMaster.com 2003-5. All Rights Reserved.
Usage implies agreement with terms.