ROBOTC.net forums
http://www.robotc.net/forums/

RobotC 3.50 bug 3
http://www.robotc.net/forums/viewtopic.php?f=63&t=4839
Page 1 of 1

Author:  MHTS [ Sat Sep 15, 2012 4:45 pm ]
Post subject:  RobotC 3.50 bug 3

Here is bug #3:
Code:
task main()
{
    nxtDisplayTextLine(0, "value=%d", 0 - 0 + 1);
}

This gave the output:
Quote:
value=-1

Author:  MHTS [ Sat Sep 15, 2012 7:04 pm ]
Post subject:  Re: RobotC 3.50 bug 3

I am trying to figure out how RobotC comes up with -1 in this scenario. Now that I looked back at bug 2 and 3, I'd bet RobotC is evaluating operators with equal precedence backwards. 0 - 0 + 1 = -1 because it is doing 0 - (0 + 1). But if that's true, I am surprise that it didn't get discovered long ago. In any case I played around with different numbers:
Code:
task main()
{
    nxtDisplayTextLine(0, "n0=%d", 0 - 0 + 1);
    nxtDisplayTextLine(1, "n1=%d", 0 - 3 + 4);
    nxtDisplayTextLine(2, "n2=%d", 3 - 4 + 5);
    nxtDisplayTextLine(3, "n3=%d", 3 * 4 + 5);
    nxtDisplayTextLine(4, "n4=%d", 3 * 4 / 5);
}

And it gave the output:
Code:
n0=-1
n1=-7
n2=-6
n3=17
n4=0

So it looks like it is evaluating it from right to left.

Author:  Dick Swan [ Mon Sep 17, 2012 2:50 pm ]
Post subject:  Re: RobotC 3.50 bug 3

Fixed for next release. ROBOTC should be compliant with C operator precedence.

Page 1 of 1 All times are UTC - 5 hours [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/