Skip to main content

IAR Embedded Workbench for Arm 9.70.x

MISRAC++2023-21.2.4

In this section:
Synopsis

(Required) The macro offsetof shall not be used

Enabled by default

Yes

Severity/Certainty

Low/Medium

lowmedium.png
Full description

Uses of the built-in function offsetof were found. This check is identical to MISRAC++2008-18-2-1, MISRAC2004-20.6.

Coding standards
MISRA C:2004 20.6

(Required) The macro offsetof in the stddef.h library shall not be used.

MISRA C++ 2008 18-2-1

(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) {
}