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.[1]
Unreachable code is sometimes also called dead code,[2][3] although dead code may also refer to code that is executed but has no effect on the output of a program.[4]
Unreachable code is generally considered undesirable for several reasons:
It uses memory unnecessarily
It can cause unnecessary use of the CPU's instruction cache
This can also decrease data locality
Time and effort may be spent testing, maintaining and documenting code which is never used
Sometimes an automated test is the only thing using the code.
However, unreachable code can have some legitimate uses, like providing a library of functions for calling or jumping to manually via a debugger while the program is halted after a breakpoint. This is particularly useful for examining and pretty-printing the internal state of the program. It may make sense to have such code in the shipped product, so that a developer can attach a debugger to a client's running instance.
^Debray, Saumya K.; Evans, William; Muth, Robert; De Sutter, Bjorn (1 March 2000). "Compiler techniques for code compaction". ACM Transactions on Programming Languages and Systems. 22 (2): 378–415. CiteSeerX 10.1.1.43.7215. doi:10.1145/349214.349233. S2CID 6129772.
^RTCA/DO-178C Software Considerations in Airborne Systems and Equipment Certification. RTCA, Inc. 2011. p. 112. Retrieved 2019-06-11. Dead code – Executable Object Code (or data) which exists as a result of a software development error but cannot be executed (code) or used (data) in any operational configuration of the target computer environment. It is not traceable to a system or software requirement. The following exceptions are often mistakenly categorized as dead code but are necessary for implementation of the requirements/design: embedded identifiers, defensive programming structures to improve robustness, and deactivated code such as unused library functions. [Since requirements-based review should identified such code as untraceable to functional requirements, static code analysis should identify such code as unreachable, and structural coverage analysis of requirements-based testing results should identify such code as unreachable, presence of unjustified dead code in a project should raise consideration of the effectiveness of the organization's development and verification processes.]
^Jay Thomas (24 January 2017). "Requirements Traceability Forms the Foundation for Thorough Software Testing". Retrieved 2019-06-11. The combination of requirements traceability with coverage analysis can also turn up areas of "dead code," or code that's never executed. This code can mostly be an inconvenience, but it can also be a security threat if a hacker can gain access and from there gain control. It's code that can't be traced and should therefore be eliminated.
^MISRA Consortium (March 2013). MISRA C:2012 Guidelines for the used of C language in critical systems. MIRA Limited. p. 41. Retrieved 2019-06-11. Rule 2.2 there shall be no dead code. Any operation that is executed but whose removal would not affect program behavior constitutes dead code.
programming, unreachablecode 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...
introduction of side-effects caused by the dead code. Dead-code elimination Redundant codeUnreachablecode Oxbow code Dead store 0xDEADC0DE is a magic number...
whether the declaration is before or after the include. To prevent unreachablecode from being added to the final executable if all uses of a function...
Where: Type must be set to 18 Code must be set to 0 Address mask should be set to the subnet mask Destination unreachable is generated by the host or its...
previously been calculated and is still available, code that is never executed (known as unreachablecode), code which is executed but has no external effect...
(HTTP) response status codes. Status codes are issued by a server in response to a client's request made to the server. It includes codes from IETF Request...
machine binary. GraalVM aggressively removes any unreachablecode found within the application's source code as well as any of its dependencies. Combined...
of middle end optimizations are removal of useless (dead-code elimination) or unreachablecode (reachability analysis), discovery and propagation of constant...
bottom, retrieved 2022-04-13 Understanding null safety - never for unreachablecode, retrieved 2022-04-13 Pierce, Benjamin C. (2002). Types and Programming...
to_string(); URL::encode(strInput); fn.result->set_string(strInput.c_str()); } In this, "strHexDigits" is oxbow code (or oxbow data). Dead codeUnreachablecode...
performed by the compiler and the exact structure of a code. In this case, the behavior of unreachablecode (the return statement) is undefined, so the compiler...
objects are garbage collected if they are unreachable from the global object. One way to make an object unreachable is to overwrite the variables or properties...
(node) of the control flow graph. Consequently, a silhouette can't have unreachablecode in any conditions. DRAKON language is used in the German Aerospace...
TRAFFICLIGHT_GREEN: return "green"; } assert(0); // Assert that this section is unreachable. // Warning: This 'assert' function call will be dropped by an optimizing...
store } } The code in the loop repeatedly overwrites the same variable, so it can be reduced to only one call. Dead codeUnreachablecode "Insecure Compiler...
elimination to remove conditionally dead or unreachablecode at load or runtime, and recombine the remaining code to minimize its memory footprint or improve...
object is stored in memory but cannot be accessed by the running code (i.e. unreachable memory). A memory leak has symptoms similar to a number of other...
about possible deficiencies or bugs, such as undefined control flow, unreachablecode, ill-formed escape symbols and potential misuse of the interface primitives...
Supplementary Service Data (USSD), sometimes referred to as "quick codes" or "feature codes", is a communications protocol used by GSM cellular telephones...
control flow analysis of the executable code within the COBOL procedure division and identify unreachablecode. The Optimizer III version of the product...
NUD may stand for: En Nahud Airport's IATA airport code Neighbor unreachability detection, a functionality of the Neighbor Discovery Protocol Niue dollar...
after the header described above. For some messages such as destination unreachable or time exceeded there is no defined message body. Others define a use...