MISRAC2004-20.6
In this section:
Synopsis
(Required) The macro offsetof in the stddef.h library shall not be used.
Enabled by default
Yes
Severity/Certainty
Low/Medium

Full description
Detected use of the built-in function offsetof. This check is identical to MISRAC++2008-18-2-1, MISRAC++2023-21.2.4.
Coding standards
- MISRA C++ 2008 18-2-1
(Required) The macro offsetof shall not be used.
- MISRA C++ 2023 21.2.4
(Required) The macro offsetof shall not be used
Code examples
The following code example fails the check and will give a warning:
#include <stddef.h>
struct stat {
int st_size;
};
int example(void) {
return offsetof(struct stat, st_size);
}
The following code example passes the check and will not give a warning about this issue:
void example(void) {
}