MISRAC2004-12.3
Synopsis
(Required) The sizeof operator shall not be used on expressions that contain side effects. The sizeof operator was found used on expressions that contain side effects. This might make it look as if the expression will be evaluated, but because sizeof only operates on the type of the expression, the expression itself is not evaluated.
Enabled by default
Yes
Severity/Certainty
Medium/Medium

Full description
Sizeof expressions were found that contain side effects. This check is identical to SIZEOF-side-effect, MISRAC++2008-5-3-4.
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.
- MISRA C++ 2008 5-3-4
(Required) Evaluation of the operand to the sizeof operator shall not 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++;
}