"if" boolean expression parse failure.

This forum is for all topics related to Simulator for Arduino v0.98. Please include sample code where possible.

Moderator: Adrian

Posts: 1
Joined: Thu Dec 20, 2012 8:18 am

"if" boolean expression parse failure.

Postby steveastrouk » Mon Dec 24, 2012 12:31 am

I have a piece of code I was testing in simulation
This is the "correct" pertinent snippet

Code: Select all

if ((Tseq & 1)==1) {digitalWrite(ledpins[0], HIGH);} else {digitalWrite(ledpins[0],LOW);}
if ((Tseq & 2)==2) {digitalWrite(ledpins[1],HIGH);} else {digitalWrite(ledpins[1] ,LOW);}

but this INcorrect snippet

Code: Select all

if (Tseq & 1==1) {digitalWrite(ledpins[0], HIGH);} else {digitalWrite(ledpins[0],LOW);}
if (Tseq & 2==2) {digitalWrite(ledpins[1],HIGH);} else {digitalWrite(ledpins[1] ,LOW);}

ALSO executes correctly in simulation, but not on the hardware.


Site Admin
Posts: 240
Joined: Thu Feb 02, 2012 6:07 pm

Re: "if" boolean expression parse failure.

Postby Simulator_admin » Fri Jan 04, 2013 8:33 pm

So this comes down to

Code: Select all

((Tseq & 1)==1) vs  (Tseq & 1==1)

We have given == higher precedence than & in the Simulator. Thanks for pointing this out - we can change this to suit the real Arduino hardware unless this is a bug in the Arduino IDE. Not sure at this stage - would you be able to ask the Arduino team if the expression on the right should work differently?

Any other comments on this are welcome.

Return to “Version 0.98”

Who is online

Users browsing this forum: No registered users and 1 guest