What is the difference between Dead code
and Deactivated code
as per DO178-b
?
Please provide some examples to highlight the difference.
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.
This means that dead code is:
Note: Unreferenced variables / functions that aren't called are not dead code, as they're automatically removed via compiler / linker.
Example:
This means that deactivated code is:
Example:
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.