Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Compilers will often delete code that has volatile stores, if it thinks that would be OK. Not everybody agrees with this policy. But they are not who makes decisions about what compilers do.

There "are always ways", but not everybody always knows what they are, or even knows they need to know them. And, what you think ought to suffice too often does not.



How can a compiler remove a volatile store? There exists hardware where a store has a side effect, regardless of the value itself. For example, writing to a FIFO. That’s the entire point of volatile, no?


You may think so, and I may even agree. But those opinions do not control what compilers actually implement.

For example, in

  void f() {
    volatile char sekrit[256];
    sekrit[0] = 0;
  }
a compiler may reason that, since sekrit is on the stack, and no hardware device could know where it is, it may elide the whole block. And, some do.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: