MISRA Discussion Forums
Shall Rule 21.1 apply to the both paths of conditional preprocessing - Printable Version

+- MISRA Discussion Forums (https://forum.misra.org.uk)
+-- Forum: MISRA C (https://forum.misra.org.uk/forumdisplay.php?fid=4)
+--- Forum: MISRA C:2012 and MISRA C:2023 guidelines (https://forum.misra.org.uk/forumdisplay.php?fid=21)
+---- Forum: 8.21 Standard libraries (https://forum.misra.org.uk/forumdisplay.php?fid=176)
+---- Thread: Shall Rule 21.1 apply to the both paths of conditional preprocessing (/showthread.php?tid=1532)



Shall Rule 21.1 apply to the both paths of conditional preprocessing - chenzhuowansui - 04-03-2020

Hi there,
Rule 21.1 doesn't mention anything about preprocessing, so given the following code
Code:
#define ABC 345

#ifdef ABC
#define _XYZ 0xFFFFFFFF    //defect1
#else
#define _XYZ 0xF0000000  //defect2
#endif

shall we report both the above defects or only the one(defec1) in the true path?

thanks


RE: Shall Rule 21.1 apply to the both paths of conditional preprocessing - misra-c - 02-07-2024

The MISRA C Glossary defines Code as:

"Code consists of everything within a translation unit that is not excluded by conditional compilation"

As such, reporting violations in active code is the requirement.

Reporting violations in inactive code is not always appropriate, as that code may not compile-able due to other considerations.