Go Down

Topic: Possible bug in arduino 1.8.5 IDE/compiler, related to if statements (Read 94 times) previous topic - next topic

Infraviolet

I think I've found a bug in the arduino IDE/compiler, I was working with version 1.8.6. I discovered it some weeks ago but have eben too busy to write this post ntil now. When I had certain kinds of statement in various if and else if conditions they compiled to do things vry different to what they should have done. I think there has ben an order of operations problem of some kind, such that I THINk the & (binary and) and | (binary or) statements were being done AFTER equality ==, greater than >, less than < or inequality != had been done.

Where I had statements like

if(Variable&B00001000 != 0){
  //do stuff
}

Where Variable was a uint8_t  I was getting the statements evaluating as true at ALL times. I had a terrible time testing the code before I had written before I relaised this was the cause of my trouble. Only when I added brackets and spacing did the statement work properly.

if( ( Variable & B00001000) != 0){

worked properly. I also found similar issues with statements containing multiple bitwise operators connected by &&, and/or || logical operators. It seems like the compiler is putting & and | in what I presume to be an incorrect order of operations.


Go Up