Skip to main content

IAR Embedded Workbench for RH850 3.20.x

CERT-EXP44-C

In this section:
Synopsis

Do not rely on side effects in operands to sizeof, _Alignof, or _Generic.

Enabled by default

Yes

Severity/Certainty

Low/Low

lowlow.png
Full description

Some operators do not evaluate their operands beyond the type information the operands provide. When using one of these operators, do not pass an operand that would otherwise yield a side effect since the side effect will not be generated. The sizeof operator yields the size (in bytes) of its operand, which may be an expression or the parenthesized name of a type. In most cases, the operand is not evaluated. The operand passed to_Alignof is never evaluated, despite not being an expression. The operand used in the controlling expression of a _Generic selection expression is never evaluated. Providing an expression that appears to produce side effects may be misleading to programmers.

Coding standards
CERT EXP44-C

Do not rely on side effects in operands to sizeof, _Alignof, or _Generic

Code examples

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

#include <stdio.h>

void func(void) {
  int a = 14;
  int b = sizeof(a++);
  printf("%d, %d\n", a, b);
}

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

#include <stdio.h>

void func(void) {
  int a = 14;
  int b = sizeof(a);
  ++a;
  printf("%d, %d\n", a, b);
}