What is the difference between Dead Code and Deactivated Code?

9.5k views Asked by At

What is the difference between Dead code and Deactivated code as per DO178-b?

Please provide some examples to highlight the difference.

2

There are 2 answers

1
Seth On

Dead code - Executable object code (or data) which, as a result of a design error, cannot be executed (code) or used (data) in an operational configuration of the target computer environment and is not traceable to a system or software requirement. An exception is embedded identifiers. Source

This means that dead code is:

  • executable code
  • software that will never be executed during runtime

Note: Unreferenced variables / functions that aren't called are not dead code, as they're automatically removed via compiler / linker.

Example:

if (true) {
    // always chosen
} else {
    // never chosen -> Dead code
}

Deactivated code - Executable object code (or data) which by design is either (a) not intended to be executed (code) or used (data), for example, a part of a previously developed software component; or (b) is only executed (code) or used (data) in certain configurations of the target computer environment, for example, code that is enabled by a hardware pin selection or software programmed options. Source

This means that deactivated code is:

  • executable code
  • software that will not be executed during runtime-operations of a certain software version / within a particular avionics box
  • software that may be executed in later versions or during special operations or only under certain circumstances

Example:

if (!option9) { // Anything but option 9 will lead to this path being chosen
    // Code
} else {
    // Code to be executed in the event that option 9 is selected
}

Note: Deactivated code can have all sorts of shapes, and this isn't what it has to look like. It basically is simply code that's not always executed, only if certain conditions are met.


I'd recommend checking out this article covering dead code / deactivated code (which also happens to be the source of the quoted text), as well as this external Q&A.

0
rallen911 On

The quoted passages in the first answer are verbatim from the DO-178B guidelines, so that is a great start.

The note on dead code is not completely accurate, though. It is compiler dependent on whether those types of things get removed. Some do it automatically. Some have options to do it or not, while still others do not even have the option.

We use deactivated code quite a bit in our designs, as we have common algorithms that use configurable parameters to activate certain aspects for one customer vs. another.

The big distinction between the two is whether there is an intended configuration that will execute the code as written. If there is, and it just isn't part of your particular project, then it would be deactivated. If there is no configuration where the code could execute, then it is considered dead.

This gets a bit tricky if you're trying to develop software to be reusable, like a device driver, when certain functions of the device are not intended to be used on the initial project. If you have requirements and develop tests for the unused code, and those get executed and tested, then it can be argued that the code is deactivated until a future project's configuration is created that will use it. Having requirements and the tests should alleviate concerns about the code if it were to execute unintentionally in the original configuration.