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

Integer data types
http://www.robotc.net/forums/viewtopic.php?f=1&t=451
Page 1 of 1

Author:  Ford Prefect [ Sat Mar 15, 2008 6:34 pm ]
Post subject:  Integer data types

in standard C I am used to the integer data types

char (-128 ... 127)
unsigned char (0 ... 255)

short (-32768 ... 32767)
unsigned short (0 ... 65535)

why do you call char "byte"
and why ain't there any unsigned integer data type?

Author:  Dick Swan [ Sat Mar 15, 2008 10:30 pm ]
Post subject: 

Both "char" and "byte" keywords should be accepted and treated identically.

ROBOTC has a built-in declaration of "typedef char byte;".

The lack of support for "unsigned" types has to do with the original ROBOTC implementation on small memory constrained platforms (vs the NXT) where there simply was inadequate memory to support the additional Virtual Machine opcodes for both "signed" and "unsigned". Adding "unsigned" support for the larger platforms like the NXT is on the wish list for new features.

The best alternative for now is to use signed long numbers for as an alternative for 16-bit unsigned. This will give you 31-bits of precision for unsigned values instead of the 16 you'll get with "unsigned short".

Author:  Ford Prefect [ Sun Mar 16, 2008 6:08 am ]
Post subject: 

hello Dick,
thx for your reply. As I alread wrote in the thread concerning "Error: out of memory"
Quote:
...it could be helpful if RobotC
char (signed byte)
declaration and conversiion to int (and back) worked without faults, because most of my map coordinates got a range from maximum -128 to 127.

so using (signed) int instead of (signed) char as you suggested, this causes a lack of available memory.
maybe you can spend a sort of VeryVerySmallSignedInt data type that is equal to ANSI char (-128...127) and needs only 2 bytes of memory.

Author:  Ford Prefect [ Sun Mar 23, 2008 7:46 am ]
Post subject: 

@Dick Swan and @all developers:

now please once more my questions, I didn't already understand the particularly given answeres
(many questions may sound redundant, but the reason is because of some inconsistence between ANSI and RobotC definitions):

(1)
what is
RobotC ubyte
and
RobotC byte?

(2)
what is corresponding in RobotC to
ANSI char (-128...127)
ANSI unsigned char (0...255)

(3)
what is the difference between
RobotC char as a figure (abcde...ABCDE...1234567890!"ยง$%&/()=?), e.g.
char f="A"
and
RobotC char as a small integer value, e.g.
char i=-120
(or is it the same? or not?)

(4)
what is the difference between
RobotC char
and
RobotC byte?

(5)
Can the positive and negative
RobotC char
or RobotC byte (?)
values meanwhile be converted correctly to int
(and smaller int values back to char? or byte?)

Author:  Dick Swan [ Tue Mar 25, 2008 5:37 am ]
Post subject: 

There are several header files declared for both programs written in ROBOTC language and for the ROBOTC IDE. The IDE is programmed in Visual Studio and accepts both 'signed' and 'unsigned'. So, ROBOTC programs accept the "unsigned" keyword and ignore with a warning if the file is not one of the system headers.

Declaration for ubyte is
Code:
typedef unsigned char ubyte;

There is no difference in ROBOTC between 'byte' and "char'. ROBOTC simply has a built-in typedef of
Code:
typedef char byte;


ROBOTC will convert between variable types "char' to "short" to "long" to "float" using the same "rules" (I hope) that standard C uses. Namely smaller variables are sign extended to larger integer variables. When "downsize" truncation is applied; i.e. the uppers bits are simply "dropped".

Author:  Ford Prefect [ Tue Mar 25, 2008 7:03 am ]
Post subject: 

so if I got it,
RobotC char = RobotC byte is unsigned char (0..255).


BUT
ANSI char is signed (-128...127)

Why is in this point RobotC totally different from ANSI ?

and what corresponds with ANSI char (-128...127) in RobotC?

Or am I maybe really dense? :(

So, how it should be, logically, and corresponding to ANSI:
char (-128...127) = signed!
byte (-128...127) = signed! (byte actually is not really needed!)

ubyte (0...255) = unsigned!

Can you please do or fix this?

Author:  Ford Prefect [ Thu Mar 27, 2008 6:36 pm ]
Post subject: 

(reminder!)

Author:  Dick Swan [ Thu Mar 27, 2008 6:55 pm ]
Post subject: 

ROBOTC only supports signed variables. I've responded multiple times to this point.

This is not going to be changed in the near future.

Continuing to keep asking this question will not change the above resolution.

Author:  Ford Prefect [ Fri Mar 28, 2008 6:04 am ]
Post subject: 

Dick, I'm sorry, but I don't get it.
It's probably because my English is very poor.
you wrote:
Quote:
ROBOTC only supports signed variables.

ok. so char is signed, and byte is signed. fine.

but you also wrote:
Quote:
typedef unsigned char ubyte;

so char=ubyte= unsigned ??? :evil:
and
Quote:
typedef char byte;

so char=byte= signed??? :evil: :evil:

and above all,
Code:
byte b;
int i;
b=-123;
i=(int)b; // gives an conversion error

i=-123
b=(byte)i; // gives also an conversion error


gives a conversion error from byte to int and back from int to byte, as if byte was unsigned!

So what is with all those contradictions?

Author:  Dick Swan [ Fri Mar 28, 2008 7:00 am ]
Post subject: 

Ford Prefect wrote:
but you also wrote:
Quote:
typedef unsigned char ubyte;

so char=ubyte= unsigned ??? :evil:
and
Quote:
typedef char byte;

...
So what is with all those contradictions?

There are no contradictions. I explained previously that ROBOTC language accepts the keyword "unsigned" because it has common files with the ROBOTC IDE that uses the Microsoft Visual Studio C compiler which does handle both 'signed' and 'unsigned' variables.

Quote:
Code:
byte b;
int i;
b=-123;
i=(int)b;
gives a conversion error from byte to int and back from int to byte, as if byte was unsigned!

THis works fine in version 1.22. There were some fixes in version 1.21 and 1.22 for byte variables so I don't know if this was a previous problem that has just been fixed.

Author:  Ford Prefect [ Fri Mar 28, 2008 10:11 am ]
Post subject: 

Dick,
please keep it simple and stupid.

I dont understand anything of the stuff you write.

Simply think you talk to a 3 years old child.
Please answer step by step explizitely:

what is the range from. . . to for

char: from. . . to
byte: from. . . to
ubyte: from. . . to

Author:  Dick Swan [ Fri Mar 28, 2008 10:37 am ]
Post subject: 

The range of any signed 1-byte (i.e. 8-bit) variable is -128 to +127.

In ROBOTC, since all variables are signed, a "char", "byte" or "ubyte" has the range.

In a future upgrade ROBOTC will support 8-bit signed (-128 to +127) variables and 8-bit unsiged (0 to 255) variables. There is no definite schedule for this upgrade.

Author:  Ford Prefect [ Fri Mar 28, 2008 10:48 am ]
Post subject: 

Thank you. :)

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