[previous] MISRA-C:2004  Rule  12.3:  (Required) [next] The sizeof operator shall not be used on expressions that contain side effects.
A possible programming error in C is to apply the sizeof operator to an expression and expect the expression to be evaluated. However the expression is not evaluated: sizeof only acts on the type of the expression. To avoid this error, sizeof shall not be used on expressions that contain side effects, as the side effects will not occur. sizeof() shall only be applied to an operand which is a type or an object. This may include volatile objects. For example:

int32_t i;
int32_t j;
j = sizeof( i = 1234 );
     /* j is set to the sizeof the type of i which is an int */
     /* i is not set to 1234.                                */


QAC messages that encompass this guideline:

3307 The operand of 'sizeof' is an expression with implied side effects, but they will not be evaluated.



(c) The Motor Industry Research Association, 2004
QA C Source Code Analyser 8.1.2
MISRA-C:2004 Compliance Module 3.2
© 2013 Programming Research
www.programmingresearch.com
Personality Groups | Glossary | Message Index | MISRA-C:2004 Rule Index Contents