MISRAC++2023-19.0.2
In this section:
Synopsis
(Required) Function-like macros shall not be defined
Enabled by default
Yes
Severity/Certainty
Low/Low

Full description
Definitions of function-like macros were found. This check is identical to MISRAC++2008-16-0-4, MISRAC2004-19.7, MISRAC2012-Dir-4.9.
Coding standards
- MISRA C:2004 19.7
(Advisory) A function should be used in preference to a function-like macro.
- MISRA C:2012 Dir-4.9
(Advisory) A function should be used in preference to a function-like macro where they are interchangeable
- MISRA C++ 2008 16-0-4
(Required) Function-like macros shall not be defined.
Code examples
The following code example fails the check and will give a warning:
#define ABS(x) ((x) < 0 ? -(x) : (x))
void example(void) {
int a;
ABS (a);
}
The following code example passes the check and will not give a warning about this issue:
template <typename T>
inline T ABS(T x) { return x < 0 ? -x : x; }