sascha432/esp8266-kfc-fw

Wire.endTransmission() and Wire.requestFrom() in a single condition ?

Closed this issue · 2 comments

Hi, I noticed that you use the Wire.endTransmission() and Wire.requestFrom() in a single condition.
It is in the 'dimmer_commands.h' file and a number of *.cpp files. In the file 'dimmer_base.cpp', even the Wire.read() is added into that.

It caught my attention, because no one does it like that.
Do you know that the order of evaluation is not specified ? https://en.cppreference.com/w/cpp/language/eval_order.
For a more clear source code, I think it might be better to keep the I2C reading and I2C writing apart.

hi,

I do not think the eval order is for && or ||... if you pass a, b, c to a function, it might be c, b, a (gcc 4.8 does it in reverse)

a && b && c should evaluate to a, then b if a is true, then c, if b is true.

so basically it is

if(a) {
  if (b) {
    if (c) {
    }
  }
}

So the order for the conditions is from left to right.
You are right. Sorry to bother you and thank you that I learned something new.