From 42a05c5f27e5ccd655dfbea7b7dede340304ccc3 Mon Sep 17 00:00:00 2001 From: Shiqing Gao Date: Tue, 30 Apr 2019 10:09:53 +0800 Subject: [PATCH] doc: add rules in C coding guidelines This patch adds rules in C coding guidelines. Signed-off-by: Shiqing Gao --- doc/developer-guides/c_coding_guidelines.rst | 24 ++++++++++++++++++++ 1 file changed, 24 insertions(+) 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 *****