Menu

#88 problem with precedences

compiler
closed-fixed
NXC (53)
5
2010-10-14
2010-10-14
Jens Erat
No

There seems to be a problem with operator precedences since version 1.2.1-r1.

(41 <= 50 && 50 < 59) evaluates to false which is obviously not intended.

I could track the problem down up to these examples:

'=>' means 'evaluates to'

(41 <= 50) => 1
(50 < 59) => 1
(1 && 1) => 1
(41 <= 50 && 50 < 59) => 0
((41 <= 50) && (50 < 59)) => 1
(1 <= 2 && 2 < 3) => 1

Beta 35 evaluates all lines to true as expected, release 1.2.1-r1 doesn't any more.

Dumping the NBC-Code and reducing it I got to this line:
41 <= ((50 != 0) && (50 < 59))

Discussion

  • John Hansen

    John Hansen - 2010-10-14

    The latest official release of the compiler (1.2.1.r4) appears to have corrected this defect. The following code plays a low A3 tone. In one of the earlier test releases I had broken the precedence of &&.
    .
    task main()
    {
    if (41 <= 50 && 50 < 59)
    PlayTone(TONE_A3, 50);
    else
    PlayTone(TONE_A7, 50);
    Wait(2000);
    }

     
  • John Hansen

    John Hansen - 2010-10-14
    • status: open --> closed-fixed