MISRAC++2023-19.3.5_a
In this section:
Synopsis
(Required) Tokens that look like a preprocessing directive shall not occur within a macro argument
Enabled by default
Yes
Severity/Certainty
High/Low

Full description
A preprocessing directive was found within a macro argument. This check is identical to CERT-PRE32-C_a, MISRAC2012-Rule-20.6_a.
Coding standards
- CERT PRE32-C
Do not use preprocessor directives in invocations of function-like macros
- MISRA C:2012 Rule-20.6
(Required) Tokens that look like a preprocessing directive shall not occur within a macro argument
Code examples
The following code example fails the check and will give a warning:
#include <string.h>
void func(const char *src) {
/* Validate the source string; calculate size */
char *dest;
/* malloc() destination string */
memcpy(dest, src,
#ifdef PLATFORM1
12
#else
24
#endif
);
/* ... */
}
The following code example passes the check and will not give a warning about this issue:
#include <string.h>
void func(const char *src) {
/* Validate the source string; calculate size */
char *dest;
/* malloc() destination string */
#ifdef PLATFORM1
memcpy(dest, src, 12);
#else
memcpy(dest, src, 24);
#endif
/* ... */
}