Rule 13.2 Compliance

Moderators: misra-c, david ward

Post Reply
rcseacord
Posts: 1
Joined: Tue Apr 19, 2016 1:55 pm
Company: NCC Group

Rule 13.2 Compliance

Post by rcseacord » Wed Mar 21, 2018 6:51 pm

Does the following expression comply with Rule 13.2?

(x = a) && (x = b)

What if it is preceded by the following declaration?

int a = 0;

Thanks,
rCs

dg1980
Posts: 109
Joined: Wed Apr 27, 2016 2:33 pm
Company: Elektrobit Automotive GmbH

Re: Rule 13.2 Compliance

Post by dg1980 » Thu Mar 22, 2018 8:32 am

Not an official answer, but this construct is highly suspicious, because the result of the assignment is used as boolean (MISRA C 2012 10.1 and 13.4).

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

Re: Rule 13.2 Compliance

Post by misra-c » Fri May 04, 2018 11:25 am

The amplification of rule 13.2 states that no object shall be modified more than once within a full expression. Therefore the code "(x = a) && (x = b)" will violate rule 13.2.

The rule does not take into account the possible values that an object might take. The initialisation of a to 0 before this line does not effect the compliance of the expression with this rule.

The expression does violate rules 10.1 (assuming int x), 13.4 and 13.5.
If the expression is preceded by "int a = 0;" the code will also violate rule 2.1. Rule 14.3 will be violated if the expression is used within a controlling expression.
---
Posted by and on behalf of
the MISRA C Working Group

Post Reply

Return to “8.13 Side effects”