Rule 13.3 incr/decr op with volatile

Moderators: misra-c, david ward

Post Reply
minhyuk
Posts: 5
Joined: Wed Feb 06, 2013 1:51 am
Company: Suresoft Technologies

Rule 13.3 incr/decr op with volatile

Post by minhyuk » Tue Jan 03, 2017 1:53 am

Hello,

Code: Select all

volatile int x;
x++; // non-compliant - because, x declared with volatile
In the above code, because 'x' variable is declared as volatile, I think it violates Rule 13.3. What do you think?

Steve Montgomery
Posts: 104
Joined: Fri Sep 17, 2004 1:31 pm
Company: .
Location: Northumberland or Isle of Skye

Re: Rule 13.3 incr/decr op with volatile

Post by Steve Montgomery » Tue Jan 03, 2017 5:24 pm

I believe that you are correct. Your example is similar to the non-compliant example in the rule

Code: Select all

g ( u8b++ );
because both this and your example have another side-effect.

Personally, I think that Rule 13.3 falls into the realm of a style guide. The rationale points out that complying with Rule 13.3 avoids some undefined behaviour. However, the same undefined behaviour, and more, is also avoided by complying with Rule 13.2. Provided that Rule 13.2 is being followed, that leaves impairment of readability as the only other rationale for Rule 13.3. I'd say that's debatable and a matter of personal preference.

Since Rule 13.2 is required and Rule 13.3 is advisory, I'd be inclined not to apply Rule 13.3 if it's causing you a problem in this situation.

minhyuk
Posts: 5
Joined: Wed Feb 06, 2013 1:51 am
Company: Suresoft Technologies

Re: Rule 13.3 incr/decr op with volatile

Post by minhyuk » Fri Jan 06, 2017 5:53 am

Steve Montgomery wrote: Since Rule 13.2 is required and Rule 13.3 is advisory, I'd be inclined not to apply Rule 13.3 if it's causing you a problem in this situation.
Thank you for your reply. I agree with you. If it is simply a rule for readability, I think we need to change the title more intuitively.

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

Re: Rule 13.3 incr/decr op with volatile

Post by misra-c » Fri Feb 03, 2017 3:35 pm

Your example does violate rule 13.3. It can be rewritten as

Code: Select all

  x = x + 1;
which complies with both rules 13.2 and 13.3.
---
Posted by and on behalf of
the MISRA C Working Group

Post Reply

Return to “8.13 Side effects”