MISRA Discussion Forums
Rule 14.2 What is meant by assign" - Printable Version

+- MISRA Discussion Forums (https://forum.misra.org.uk)
+-- Forum: MISRA C (https://forum.misra.org.uk/forumdisplay.php?fid=4)
+--- Forum: MISRA C:2012 and MISRA C:2023 guidelines (https://forum.misra.org.uk/forumdisplay.php?fid=21)
+---- Forum: 8.14 Control statement expressions (https://forum.misra.org.uk/forumdisplay.php?fid=169)
+---- Thread: Rule 14.2 What is meant by assign" (/showthread.php?tid=1149)



Rule 14.2 What is meant by assign" - misra-c - 13-02-2015

In the 1st clause what is meant by “assign a value to the loop counter”. May this “value” be an expression with side-effects?
Code:
int index;
for ( set_val(&index) ;  index < 10 ; index++) // Is this compliant if set_val assigns to index
Note: the 2nd and 3rd clauses explicitly refer to expressions and whether side-effects are permitted.


Re: Rule 14.2 What is meant by assign" - misra-c - 13-02-2015

The first clause may assign a value to the loop counter via a function call which includes persistent side-effects.

The above example is compliant with this rule.