MISRA Discussion Forums
MISRA 20.2 - 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: 2004 rules (https://forum.misra.org.uk/forumdisplay.php?fid=17)
+---- Forum: 6.20 Standard Libraries (https://forum.misra.org.uk/forumdisplay.php?fid=42)
+---- Thread: MISRA 20.2 (/showthread.php?tid=1419)



MISRA 20.2 - ankitshah413 - 26-04-2018

Hello,

Why the following code is the violation of MISRA 20.2 ?

Code:
#define abs(a)   (((a) < (0)) ? -(a) : (a))

As far as I understand from the topics , 20.2 does not concern with preprocessor identifier then why I get an violation for the same.


Re: MISRA 20.2 - misra-c - 04-05-2018

Rule 20.2 refers to the declaration of non-preprocessor names. i.e. objects, function names, typedefs. This code is not a violation of rule 20.2, but does violate rule 20.1 which does not permit standard library functions to be used in a #define.