Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Adding const qualification may propagate through a program; as you add const qualifiers, still more become necessary. This phenomenon is sometimes called "const-poisoning." Const-poisoning can frequently lead to violations of EXP05-A. Do not cast away a const qualification. While const qualification is a good idea, the costs may outweigh the value in the remediation of existing code.

One may wish to consider using a macro, or an enumeration constant, rather than a const variable, see DCL06-A. Use meaningful symbolic constants to represent literal values in program logic for details regarding macros vs. enumeration constants vs. const variables. However, adding a const qualifier to a pre-existing variable is a better first step than replacing the variable with an enumeration constant or macro, because the compiler can then issue warnings on any code that changes your const variable. Once you have verified that a const variable indeed is not changed by any code, you may then consider changing it to an enumeration constant or macro, as best fits your design.

Non-Compliant Code Example

...