MISRA Discussion Forums
Rule 13.3 - Using ++/-- with a volatile variable in C - 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 - Using ++/-- with a volatile variable in C (/showthread.php?tid=1671)



Rule 13.3 - Using ++/-- with a volatile variable in C - bsmith23 - 06-02-2024

Hello, 
I saw in a previous post (https://forum.misra.org.uk/showthread.php?tid=1302), it was discussed that 
Code:
volatile int x = 0;
x++;
where x is declared as volatile is a violation of rule 13.3 and changing this to be 
Code:
x += 1;
results in compliance with rule 13.3. Would someone be able to explain why this is the case?


RE: Rule 13.3 - Using ++/-- with a volatile variable in C - misra-c - 10-07-2025

Accessing a volatile has potential side effects, beyond the simple read operation - hence the violation of Rule 13.3.

x += 1 does not violate Rule 13.3, because that Rule explicitly only applies to ++ and --, and not to += or -=