View unanswered posts | View active topics It is currently Sun Nov 23, 2014 6:54 am






Reply to topic  [ 3 posts ] 
RobotC 3.50 bug 3 
Author Message
Guru
User avatar

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1347
Post 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


Sat Sep 15, 2012 4:45 pm
Profile
Guru
User avatar

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1347
Post 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.


Sat Sep 15, 2012 7:04 pm
Profile
Creator
Creator

Joined: Fri Feb 09, 2007 9:21 am
Posts: 615
Post Re: RobotC 3.50 bug 3
Fixed for next release. ROBOTC should be compliant with C operator precedence.


Mon Sep 17, 2012 2:50 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 3 posts ] 

Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron



Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.