Weitere Beispiele werden automatisch zu den Stichwörtern zugeordnet - wir garantieren ihre Korrektheit nicht.
The existence of unreachable code can be due to various factors, such as:
Unreachable code is generally considered undesirable for a number of reasons, including:
This is in contrast to unreachable code analysis which is based on control flow analysis.
The optimization that removes unreachable code is known as dead code elimination.
In practice the sophistication of the analysis performed has a significant impact on the amount of unreachable code that is detected.
In some languages (e.g. Java ) some forms of unreachable code are explicitly disallowed.
This examines the program structure, identifying key features: Entry/Exit points, Loops, Branches and unreachable code.
(ICMP unreachable code )
Profiling in general can not prove anything about the unreachability of a piece of code, but may be a good heuristic for finding potentially unreachable code.
The unreachable code elimination technique is in the same class of optimizations as dead code elimination and redundant code elimination.
However, in practise it is also common for code sections to represent dead or unreachable code only under certain conditions, which may not be known at the time of compilation.
Unreachable code is sometimes also called dead code, although dead code may also refer to code that is executed but has no effect on the output of a 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.
In this case, the behavior of unreachable code (the return statement) is undefined, so the compiler can eliminate it and use a tail call optimization that might result in no stack usage.
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.
If a subgraph is not connected from the subgraph containing the entry block, that subgraph is unreachable during any execution, and so is unreachable code; under normal conditions it can be safely removed.
Detecting unreachable code is a form of static analysis and involves performing control flow analysis to find any code that will never be executed regardless of the values of variables and other conditions at run time.
Duck typing can also be more flexible in that only the methods 'actually called at run time' need to be implemented, while templates require implementation of all methods that 'cannot be proven Unreachable code at compile time'.
Typical transformations for optimization are removal of useless or unreachable code, discovery and propagation of constant values, relocation of computation to a less frequently executed place (e.g., out of a loop), or specialization of computation based on the context.
An example of such a conditionally unreachable code may be the implementation of a printf() function in a compiler's runtime library, which contains complex code to process all possible string arguments, of which only a small subset is actually used in the program.
Unreachable code and infinite loops are possible even if the programmer does not explicitly code them: optimizations like constant propagation and constant folding followed by jump threading can collapse multiple basic blocks into one, cause edges to be removed from a CFG, etc., thus possibly disconnecting parts of the graph.