Next: High Integrity CPP Rule 10.2  Up: 10 Expressions  Previous: 10 Expressions  Contents

High Integrity CPP Rule 10.1   Use symbolic names instead of literal values in code. Do not use "magic" numbers.
(QA C++  4400, 4401, 4402, 4403, 4404)

Justification

By eliminating "magic" numbers from the body of the code and placing them in header files, the code becomes easier to maintain. Symbolic names should be self documenting.

Exception

Literals with intuitive meaning: the character literal '\0', numeric literals 0 & 1 and the boolean literals true and false.

String literals that only occur in the code once. This exception does not apply where there is a requirement for internationalisation.

Reference

Industrial Strength C++ 5.4;


HICPP VERSION 2.4  http://www.codingstandard.com   Copyright: © 2007 THE PROGRAMMING RESEARCH GROUP