The C Standard says
An actual implementation need not evaluate part of an expression if it can deduce that its value is not used and that no needed side effects are produced (including any caused by calling a function or accessing a volatile object)
When is a volatile
variable not needed? According to this paragraph, volatile
appears to become subject to the as-if rule just like any other non-volatile
object.
The answers given in the non-duplicate linked question are not helpful to me as they do not address the above quoted paragraph
- When is a value considered to be "used"? It appears to be different than "reading the value from an object" because the corresponding access can be omitted, according to the above quote.
- What is a "needed side effect"?
Refer to the comments below.