View unanswered posts | View active topics It is currently Thu Aug 21, 2014 4:51 am






Reply to topic  [ 13 posts ] 
Integer data types 
Author Message
Guru
User avatar

Joined: Sat Mar 01, 2008 12:52 pm
Posts: 1030
Post 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?

_________________
regards,
HaWe aka Ford
#define S sqrt(t+2*i*i)<2
#define F(a,b) for(a=0;a<b;++a)
float x,y,r,i,s,j,t,n;task main(){F(y,64){F(x,99){r=i=t=0;s=x/33-2;j=y/32-1;F(n,50&S){t=r*r-i*i;i=2*r*i+j;r=t+s;}if(S){PutPixel(x,y);}}}while(1)}


Sat Mar 15, 2008 6:34 pm
Profile
Creator
Creator

Joined: Fri Feb 09, 2007 9:21 am
Posts: 614
Post 
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".


Sat Mar 15, 2008 10:30 pm
Profile
Guru
User avatar

Joined: Sat Mar 01, 2008 12:52 pm
Posts: 1030
Post 
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.

_________________
regards,
HaWe aka Ford
#define S sqrt(t+2*i*i)<2
#define F(a,b) for(a=0;a<b;++a)
float x,y,r,i,s,j,t,n;task main(){F(y,64){F(x,99){r=i=t=0;s=x/33-2;j=y/32-1;F(n,50&S){t=r*r-i*i;i=2*r*i+j;r=t+s;}if(S){PutPixel(x,y);}}}while(1)}


Sun Mar 16, 2008 6:08 am
Profile
Guru
User avatar

Joined: Sat Mar 01, 2008 12:52 pm
Posts: 1030
Post 
@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?)

_________________
regards,
HaWe aka Ford
#define S sqrt(t+2*i*i)<2
#define F(a,b) for(a=0;a<b;++a)
float x,y,r,i,s,j,t,n;task main(){F(y,64){F(x,99){r=i=t=0;s=x/33-2;j=y/32-1;F(n,50&S){t=r*r-i*i;i=2*r*i+j;r=t+s;}if(S){PutPixel(x,y);}}}while(1)}


Sun Mar 23, 2008 7:46 am
Profile
Creator
Creator

Joined: Fri Feb 09, 2007 9:21 am
Posts: 614
Post 
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".


Tue Mar 25, 2008 5:37 am
Profile
Guru
User avatar

Joined: Sat Mar 01, 2008 12:52 pm
Posts: 1030
Post 
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?

_________________
regards,
HaWe aka Ford
#define S sqrt(t+2*i*i)<2
#define F(a,b) for(a=0;a<b;++a)
float x,y,r,i,s,j,t,n;task main(){F(y,64){F(x,99){r=i=t=0;s=x/33-2;j=y/32-1;F(n,50&S){t=r*r-i*i;i=2*r*i+j;r=t+s;}if(S){PutPixel(x,y);}}}while(1)}


Tue Mar 25, 2008 7:03 am
Profile
Guru
User avatar

Joined: Sat Mar 01, 2008 12:52 pm
Posts: 1030
Post 
(reminder!)

_________________
regards,
HaWe aka Ford
#define S sqrt(t+2*i*i)<2
#define F(a,b) for(a=0;a<b;++a)
float x,y,r,i,s,j,t,n;task main(){F(y,64){F(x,99){r=i=t=0;s=x/33-2;j=y/32-1;F(n,50&S){t=r*r-i*i;i=2*r*i+j;r=t+s;}if(S){PutPixel(x,y);}}}while(1)}


Thu Mar 27, 2008 6:36 pm
Profile
Creator
Creator

Joined: Fri Feb 09, 2007 9:21 am
Posts: 614
Post 
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.


Thu Mar 27, 2008 6:55 pm
Profile
Guru
User avatar

Joined: Sat Mar 01, 2008 12:52 pm
Posts: 1030
Post 
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?

_________________
regards,
HaWe aka Ford
#define S sqrt(t+2*i*i)<2
#define F(a,b) for(a=0;a<b;++a)
float x,y,r,i,s,j,t,n;task main(){F(y,64){F(x,99){r=i=t=0;s=x/33-2;j=y/32-1;F(n,50&S){t=r*r-i*i;i=2*r*i+j;r=t+s;}if(S){PutPixel(x,y);}}}while(1)}


Fri Mar 28, 2008 6:04 am
Profile
Creator
Creator

Joined: Fri Feb 09, 2007 9:21 am
Posts: 614
Post 
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.


Fri Mar 28, 2008 7:00 am
Profile
Guru
User avatar

Joined: Sat Mar 01, 2008 12:52 pm
Posts: 1030
Post 
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

_________________
regards,
HaWe aka Ford
#define S sqrt(t+2*i*i)<2
#define F(a,b) for(a=0;a<b;++a)
float x,y,r,i,s,j,t,n;task main(){F(y,64){F(x,99){r=i=t=0;s=x/33-2;j=y/32-1;F(n,50&S){t=r*r-i*i;i=2*r*i+j;r=t+s;}if(S){PutPixel(x,y);}}}while(1)}


Fri Mar 28, 2008 10:11 am
Profile
Creator
Creator

Joined: Fri Feb 09, 2007 9:21 am
Posts: 614
Post 
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.


Fri Mar 28, 2008 10:37 am
Profile
Guru
User avatar

Joined: Sat Mar 01, 2008 12:52 pm
Posts: 1030
Post 
Thank you. :)

_________________
regards,
HaWe aka Ford
#define S sqrt(t+2*i*i)<2
#define F(a,b) for(a=0;a<b;++a)
float x,y,r,i,s,j,t,n;task main(){F(y,64){F(x,99){r=i=t=0;s=x/33-2;j=y/32-1;F(n,50&S){t=r*r-i*i;i=2*r*i+j;r=t+s;}if(S){PutPixel(x,y);}}}while(1)}


Fri Mar 28, 2008 10:48 am
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 13 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.