View unanswered posts | View active topics It is currently Tue Oct 21, 2014 10:33 am






Reply to topic  [ 3 posts ] 
order of parsing expressions 
Author Message
Rookie
User avatar

Joined: Sun Jun 17, 2012 11:18 am
Posts: 26
Post order of parsing expressions
Hi guys, I come across a really confusing problem. I have a function as below:

Code:
void mSetInstantMotion(float vx, float vy, float r){
   int a = (int)(r + vx);
   int b = (int)(r-1*vx-2*vy);
   int c = (int)(r-1*vx+2*vy);

   motor[motorA] = a;
   motor[motorB] = b;
   motor[motorC] = c;
   while(true){EndTimeSlice();}

}


Very simple. But from a snapshot of the local variables, i see:
Quote:
vx 50
vy 50
r 0
a 50
b 50
c -150


It doesn't match what I'm expect. It should be b = 0 - 50 -2*50 = -150 right? Also wrong for c = 0 - 50 + 2*50 = 50

It becomes correct if i parenthesize each product term, as below

Code:
void mSetInstantMotion(float vx, float vy, float r){
   int a = (int)(r + vx);
   int b = (int)(r-(1*vx)-(2*vy));
   int c = (int)(r-(1*vx)+(2*vy));

   motor[motorA] = a;
   motor[motorB] = b;
   motor[motorC] = c;
   while(true){EndTimeSlice();}

}

But this should not be necessary. It seems the compiler evaluates an expression from right to left, which seems awkward. Do you have any ideas about this?


Thu Oct 11, 2012 12:41 pm
Profile
Guru
User avatar

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1347
Post Re: order of parsing expressions
This has been fixed for the latest build. Please refer to the following post.
viewtopic.php?f=63&t=4839


Thu Oct 11, 2012 1:11 pm
Profile
Site Admin
Site Admin

Joined: Wed Jan 24, 2007 10:42 am
Posts: 613
Post Re: order of parsing expressions
Just to clarify - this issue was resolved in ROBOTC 3.51.

Thanks!

_________________
Timothy Friez
ROBOTC Developer - SW Engineer
tfriez@robotc.net


Thu Oct 11, 2012 1:39 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:  



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