|Integer data types
|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 ]|
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 ]|
thx for your reply. As I alread wrote in the thread concerning "Error: out of memory"
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 ]|
@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):
what is corresponding in RobotC to
ANSI char (-128...127)
ANSI unsigned char (0...255)
what is the difference between
RobotC char as a figure (abcde...ABCDE...1234567890!"§$%&/()=?), e.g.
RobotC char as a small integer value, e.g.
(or is it the same? or not?)
what is the difference between
Can the positive and negative
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 ]|
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
There is no difference in ROBOTC between 'byte' and "char'. ROBOTC simply has a built-in typedef of
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 ]|
so if I got it,
RobotC char = RobotC byte is unsigned char (0..255).
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 ]|
|Author:||Dick Swan [ Thu Mar 27, 2008 6:55 pm ]|
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 ]|
Dick, I'm sorry, but I don't get it.
It's probably because my English is very poor.
ok. so char is signed, and byte is signed. fine.
but you also wrote:
so char=ubyte= unsigned ???
so char=byte= signed???
and above all,
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 ]|
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.
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 ]|
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 ]|
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 ]|
|Page 1 of 1||All times are UTC - 5 hours [ DST ]|
|Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group