View unanswered posts | View active topics It is currently Thu Dec 18, 2014 7:08 pm






Reply to topic  [ 2 posts ] 
RobotC 8.23 firmware fails with unsigned values 
Author Message
Rookie
User avatar

Joined: Fri Mar 21, 2008 8:00 pm
Posts: 20
Location: Spain
Post RobotC 8.23 firmware fails with unsigned values
I have a problem with the unsigned values that in previouse version works well:

task main()
{
nxtDisplayTextLine(1, "%d",255);
while (true);
}

This code shows in the NXT window: 1680147487

and with this code:

task main()
{
byte a=255;
nxtDisplayTextLine(1, "%i",(unsigned int)a);
while (true);
}

The result is: -1

_________________
Nobody knows what you're capable ... until you get down to it.


Tue Jan 29, 2013 12:36 pm
Profile WWW
Site Admin
Site Admin

Joined: Wed Jan 24, 2007 10:42 am
Posts: 616
Post Re: RobotC 8.23 firmware fails with unsigned values
The compiler is calculating this correctly. a "byte" is the same as a "char" which has a range of -128 to +127. When you assign a value of 255, it will overflow and end up with a value of -1.

Here is proof from a GCC compiler which exhibits the same behavior. http://i.imgur.com/BQQ7yQZ.png

Try using a ubyte instead which has a range of 0-255 and will be able to store your value.

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


Wed Jan 30, 2013 10:23 am
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 2 posts ] 

Who is online

Users browsing this forum: No registered users and 1 guest


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.