Skip to main content

IAR Embedded Workbench for RH850 3.20.x

MISRAC++2023-12.3.1

In this section:
Synopsis

(Required) The union keyword shall not be used

Enabled by default

Yes

Severity/Certainty

Low/Medium

lowmedium.png
Full description

Unions were found. This check is identical to MISRAC++2008-9-5-1, MISRAC2004-18.4, MISRAC2012-Rule-19.2.

Coding standards
MISRA C:2004 18.4

(Required) Unions shall not be used.

MISRA C:2012 Rule-19.2

(Advisory) The union keyword should not be used

MISRA C++ 2008 9-5-1

(Required) Unions shall not be used.

Code examples

The following code example fails the check and will give a warning:

union cheat {
  int   i;
  float f;
};

int example(float f) {
  union cheat u;
  u.f = f;
  return u.i;
}

The following code example passes the check and will not give a warning about this issue:

int example(int x) {
  return x;
}