MISRA C:2023 Rule 13.6
The operand of the sizeof operator shall not contain any expression which has potential side effects
Since R2024a
Description
Rule Definition
The operand of the sizeof operator shall not contain any expression which has potential side effects1 .
Rationale
The argument of a sizeof
operator is usually
not evaluated at run time. If the argument is an expression, you might
wrongly expect that the expression is evaluated.
Polyspace Implementation
The rule checker reports a violation if the operand of a sizeof
operator has side effects that persist beyond the sizeof
expression. For
instance, if the sizeof
operator increments a global variable, the rule
checker reports a violation.
Troubleshooting
If you expect a rule violation but do not see it, refer to Diagnose Why Coding Standard Violations Do Not Appear as Expected.
Examples
Check Information
Group: Side Effects |
Category: Required |
AGC Category: Required |
Version History
Introduced in R2024a
See Also
1 All MISRA coding rules and directives are © Copyright The MISRA Consortium Limited 2021.
The MISRA coding standards referenced in the Polyspace® Bug Finder™ documentation are from the following MISRA standards:
MISRA C:2004
MISRA C:2012
MISRA C:2023
MISRA C++:2008
MISRA C++:2023
MISRA and MISRA C are registered trademarks of The MISRA Consortium Limited 2021.