Rule 13.3 incr/decr op with volatile - 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.13 Side effects (https://forum.misra.org.uk/forumdisplay.php?fid=168) +---- Thread: Rule 13.3 incr/decr op with volatile (/showthread.php?tid=1302) |
Rule 13.3 incr/decr op with volatile - minhyuk - 03-01-2017 Hello, Code: volatile int x; In the above code, because 'x' variable is declared as volatile, I think it violates Rule 13.3. What do you think? Re: Rule 13.3 incr/decr op with volatile - Steve Montgomery - 03-01-2017 I believe that you are correct. Your example is similar to the non-compliant example in the rule Code: g ( u8b++ ); 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. Re: Rule 13.3 incr/decr op with volatile - minhyuk - 06-01-2017 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. Re: Rule 13.3 incr/decr op with volatile - misra-c - 03-02-2017 Your example does violate rule 13.3. It can be rewritten as Code: x = x + 1; RE: Rule 13.3 incr/decr op with volatile - bsmith23 - 30-01-2024 (03-02-2017, 03:35 PM)misra-c Wrote: Your example does violate rule 13.3. It can be rewritten as Hello, would you be able to explain why the above code snippet is compliant with 13.2 and 13.3? Is the rationale that it is not using ++/--? |