Rule 14.2 What is meant by assign"

Moderators: misra-c, david ward

Post Reply
misra-c
Posts: 566
Joined: Thu Jan 05, 2006 1:11 pm

Rule 14.2 What is meant by assign"

Post by misra-c » Fri Feb 13, 2015 12:15 pm

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: Select all

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.
---
Posted by and on behalf of
the MISRA C Working Group

misra-c
Posts: 566
Joined: Thu Jan 05, 2006 1:11 pm

Re: Rule 14.2 What is meant by assign"

Post by misra-c » Fri Feb 13, 2015 12:18 pm

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.
---
Posted by and on behalf of
the MISRA C Working Group

Post Reply

Return to “8.14 Control statement expressions”