Quantcast
Channel: Can volatile variables be read multiple times between sequence points? - Stack Overflow
Viewing all articles
Browse latest Browse all 7

Answer by 0___________ for Can volatile variables be read multiple times between sequence points?

$
0
0

IMO it is legal but very bad.

    int new_thing = thingy - (thingy + thingy);

Multiple use of volatile variables in one expression is allowed and no warning is needed. But from the programmer's point of view, it is a very bad line of code.

Does this mean the expressions like x = volatile_var - (volatile_var +volatile_var) is undefined ? Should my compiler throw an error if thisoccurs ?

No as C standard does not say anything how those reads have to be ordered. It is left to the implementations. All known to me implementations do it the easiest way for them like in this example : https://godbolt.org/z/99498141d


Viewing all articles
Browse latest Browse all 7

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>