In the spirit of undefined behavior associated with sequence points such as “x = ++x” is it really undefined?, how does one get the compiler to complain about such code?
Specifically, I am using Visual Studio 2010 and Xcode 4.3.1, the latter for an OSX app, and neither warned me about this. I even cranked up the warnings on VS2010 to "all", and it happily compiled this. (For the record, VS2010's version added 1 to the variable where Xcode's version kept the variable unchanged.)
AFAIK, Visual Studio does not detect such situations. And I'm personally not convinced that there's much point in doing that. I'd say that a warning for a fairly obvious case like that would have mostly educational value, but not much practical value. In general case the issue in question takes place in situations like *p = ++*q
when p
and q
happen to point to the same object. Needless to say, they are not detectable by the compiler.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With