Closed yumkam closed 3 years ago
I agree, evaluation order is undefined, but | (binary or) is commutative (a|b is the same as b|a), thus operation order is not important. So there should be no need for modification.
Wrong. It is not a|b
(which would be symmetric), it is (a<<8)|b
or (b<<8)|a
(totally different).
I agree! The order of calling those functions is important: spixfer(0); and _wire->read(); And the order of calling those functions is not defined. So currently it depends on the compiler if the version without your pull request works or not! Thanks for explaining.
So currently it depends on the compiler if the version without your pull request works or not!
That doesn't sound like a change we want to make.
@thijstriemstra The point @espHorst was making is that the current code exhibits undefined behaviour (it might swap the MSB and LSB of a read 16 bit number), depending on the C compiler (and version) used. The pull requester proposes to fix it.
The pull requester proposes to fix it.
I see!
Closing this. Looks like a potentially interesting bug. But the updates for #96 will likely change this code anyway.
Expression evaluation order is undefined in C/C++ (except for short-circuits in && || and ?: )
Beware: not even compile-tested!