Does this paragraph allow an implementation to optimize out volatile accesses in C? -


this question has answer here:

the c standard says

an actual implementation need not evaluate part of expression if can deduce value not used , no needed side effects produced (including caused calling function or accessing volatile object)

when volatile variable not needed? according paragraph, volatile appears become subject as-if rule other non-volatile object.


the answers given in non-duplicate linked question not helpful me not address above quoted paragraph

  • when value considered "used"? appears different "reading value object" because corresponding access can omitted, according above quote.
  • what "needed side effect"?

refer comments below.

i think they're referring situations like

void test(int volatile *y) {     int x = *y; }  int main(void) {     test(some_volatile_y);     return 0; } 

where load memory optimized away (unevaluated), because result not needed on every implementation. (of course, on implementations memory load can trigger event, of course result "needed" , cannot optimized away.)


thanks alex's comment below pointing out footnote in c standard (c99: 6.7.3 type qualifiers: footnote 114):

a volatile declaration may used describe object corresponding memory-mapped input/output port or object accessed asynchronously interrupting function. actions on objects declared shall not ‘‘optimized out’’ implementation or reordered except permitted rules evaluating expressions.

note says may -- it's giving example. clause j.3 mentions constitutes access object has volatile-qualified type implementation-defined, makes sense: previous clause example of "access" could mean, mean else depending on implementation.

so, on implementations system knows can't cause needed side effect, volatile access may removed.


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -