MISRA Discussion Forums

Full Version: MISRA 20.2
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

Why the following code is the violation of MISRA 20.2 ?

#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.
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.