diff --git a/doc/developer-guides/c_coding_guidelines.rst b/doc/developer-guides/c_coding_guidelines.rst index a55759d5d..0ca72d61e 100644 --- a/doc/developer-guides/c_coding_guidelines.rst +++ b/doc/developer-guides/c_coding_guidelines.rst @@ -1832,6 +1832,30 @@ Compliant example:: showcase_a++, showcase_b++; +C-EP-22: Magic numbers shall be used with restrictions +====================================================== + +Only the following cases shall be allowed: + +a) The magic number is defined as a MACRO with a name clearly indicating its + meaning. +b) The meaning of the magic number is clearly documented in the comments before + its usage. +c) The meaning of the magic number is straightforward in the specific context. + +Compliant example:: + + #define APIC_ID_MASK 0xff000000U + + uint32_t showcase = APIC_ID_MASK; + +.. rst-class:: non-compliant-code + + Non-compliant example:: + + uint32_t showcase = 0xff000000U; + + Types *****