I've read this:
- Undefined behavior and sequence points
- Undefined behavior and sequence points reloaded
- Sequence Points and Method Chaining
- GCC bug? Chaining methods, broken sequence point
...but I'm still not sure how this should behave:
int should_be_zero
= stream.seek(4).read_integer()
- stream.seek(4).read_integer();
Stream::seek() returns *this and seek/read_integer() respectively call fseek/fread on some FILE*.
This should return 0 like this:
stream.seek(4)stream.read_integer()(at position 4, returnsX, stream position advanced to 8)stream.seek(4)stream.read_integer()(at position 4, returnsY == X)X - Y == 0
This worked well for me on gcc, MinGW and MinGW-w64. But when I decided to extend compiler support for MSVC, I discovered that this doesn't work anymore and returns garbage values. Here's what actually happens on MSVC:
stream.seek(4)stream.seek(4)(again)stream.read_integer()(at position 4, returnsX, stream position advanced to 8)stream.read_integer()(at position 8, returnsY != X)X - Y != 0
Is such execution order well defined? If not, how can I protect myself against shooting myself in the foot like this in the future?
(Wrapping the calls with brackets doesn't seem to do anything.)