MISRAC++2008-5-3-4
In this section:
Synopsis
(Required) Evaluation of the operand to the sizeof operator shall not contain side effects.
Enabled by default
Yes
Severity/Certainty
Medium/Medium

Full description
There are sizeof expressions that contain side effects. This check is identical to SIZEOF-side-effect, MISRAC2004-12.3.
Coding standards
- CERT EXP06-C
Operands to the sizeof operator should not contain side effects
- CERT EXP06-CPP
Operands to the sizeof operator should not contain side effects
- MISRA C:2004 12.3
(Required) The sizeof operator shall not be used on expressions that contain side effects.
Code examples
The following code example fails the check and will give a warning:
void example(void) {
int i;
int size = sizeof(i++);
}
The following code example passes the check and will not give a warning about this issue:
void example(void) {
int i;
int size = sizeof(i);
i++;
}