View unanswered posts | View active topics It is currently Fri Apr 29, 2016 4:16 am

 Page 1 of 1 [ 3 posts ]
 Print view Previous topic | Next topic
order of parsing expressions
Author Message
Rookie

Joined: Sun Jun 17, 2012 11:18 am
Posts: 26
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 50vy 50r 0a 50b 50c -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
Guru

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

Joined: Wed Jan 24, 2007 10:42 am
Posts: 620
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
Display posts from previous:  Sort by
 Page 1 of 1 [ 3 posts ]

#### Who is online

Users browsing this forum: JessicaCrane33 and 1 guest

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

Search for:
 Jump to:  Select a forum ------------------ ROBOTC Applications    ROBOTC for LEGO MINDSTORMS       Third-party sensors    ROBOTC for CORTEX & PIC    ROBOTC for VEX IQ    ROBOTC for Arduino    Robot Virtual Worlds    Multi-Robot Communications    Issues and Bugs Competitions & Partners    Mini Urban Challenge    CS2N Robot Virtual Worlds Competitions       VEX Skyrise Competition 2014-2015       VEX Toss Up 2013-2014       FTC Block Party! 2013-2014    Competitions using VEX - BEST, TSA, VEX, and RoboFest!    FTC Programming    RoboCup Junior and Other ROBOT Competitions Virtual Brick Robotics Discussions    General Discussions    Project Discussions Off-Topic ROBOTC Forum & ROBOTC.net Suggestions/Feedback    ROBOTC Forums Suggestions/Comments    ROBOTC.net Suggestions/Comments       NXT Programming: Tips for Beginning with ROBOTC       VEX Programming: Tips for Beginning with ROBOTC    2013 Robotics Summer Of Learning       VEX Toss Up Programming Challenge       FTC Ring It Up! Programming Challenge    International Forums       Spanish Forums          ROBOTC for MINDSTORMS          ROBOTC for VEX       French Forums          ROBOTC pour Mindstorms          ROBOTC pour IFI VEX       Japanese Forums （日本語のフォーラム）       German Forums    2015 Spring Carnival Event    PLTW (Project Lead The Way)    Robotics Merit Badge    2014 Robotics Academy Summer of Learning