switchdoclabs / SDL_Arduino_INA3221

Corrected SDL_Arduino_INA3221
GNU General Public License v2.0
82 stars 23 forks source link

Evaluation order is not guaranteed #2

Open ChristopheLorenz opened 6 years ago

ChristopheLorenz commented 6 years ago

In the source SDL_Arduino_INA3221.cpp

Line 71 : *value = ((Wire.receive() << 8) | Wire.receive());

While it works -now- it's bad design because evaluation order is not guaranteed in c++. So it could evaluate left->right or right->left depending on compiler brand/version/settings used.

You should split it into 2 lines to force the order : value = ((TinyWireM.read() << 8); value = | TinyWireM.read());

I once faced that same problem while switching from gcc to intel compiler which evaluates right->left.

jamesmyatt commented 4 years ago

@christophelorenz, it might help if you make a pull request.