View unanswered posts | View active topics It is currently Thu Oct 02, 2014 6:28 am






Reply to topic  [ 8 posts ] 
1.17/1.22: display + direct assignment byte to int and back? 
Author Message
Guru
User avatar

Joined: Sat Mar 01, 2008 12:52 pm
Posts: 1030
Post 1.17/1.22: display + direct assignment byte to int and back?
Hi,
because of many crushes with the last betas
I'd like to know if someone may test, if direct display and conversion (assignment) frombyte to int (and back) are now possible, just like
Code:
int i, j;
byte b, c;

task main() {
b=-120;
nxtDisplayTextLine(0, "Byte b= %4d", b);
i=b;
nxtDisplayTextLine(1, "int  i= %4d", i);

j=-99;
nxtDisplayTextLine(3, "int  j= %4d", j);
c=j;
nxtDisplayTextLine(4, "Byte c= %4d", c);

while(true) {wait1Msec(50);}
}


In ANSI C this should work, (int, byte, char, short, and long all are integer variables!) but with RobotC (1.10) I consistently get compiler or runtime errors, so I'd like to know if the bug has been removed meanwhile.
And because of several other beta 1.17 and 1.22 bugs I can't test this by my own :(

Thanks in advance!

_________________
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)}


Last edited by Ford Prefect on Fri Apr 04, 2008 3:30 am, edited 10 times in total.



Wed Apr 02, 2008 11:12 am
Profile
Guru
User avatar

Joined: Sat Mar 01, 2008 12:52 pm
Posts: 1030
Post 
(PS: new test file above)

_________________
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)}


Wed Apr 02, 2008 12:12 pm
Profile
Rookie

Joined: Fri Apr 20, 2007 3:22 am
Posts: 36
Post 
I don't believe that would work in ansi c, at least it shouldn't.

When doing type conversions you should always specify the type.

Code:

task main()
{
   int a,b;
   byte i,j;

   a= 45;
   i =123;

   j=(byte)a;
   b=(int)i;

   nxtDisplayTextLine(0,"a=%d",a);
   nxtDisplayTextLine(1,"b=%d",b);
   nxtDisplayTextLine(2,"i=%d",(int)i);
   nxtDisplayTextLine(3,"j=%d",(int)j);
   while(1);

}
[/code]


Sun Apr 06, 2008 7:55 pm
Profile
Guru
User avatar

Joined: Sat Mar 01, 2008 12:52 pm
Posts: 1030
Post 
in ANSI C you don't have to do type conversion!
You could write
Code:
signed char b;  // (signed) char = "byte" in RobotC!!
printf("b= %d",b);

and it works!
and it should work just because char (byte) is nothing else but a small integer!

_________________
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)}


Mon Apr 07, 2008 2:53 am
Profile
Rookie

Joined: Fri Apr 20, 2007 3:22 am
Posts: 36
Post 
Ford Prefect wrote:
and it should work just because char (byte) is nothing else but a small integer!


which would create truncation errors.
You should always be aware of mixing data types which is why you should always have type conversions.

There are a lot of versions of c out there that allow you to mix bytes and ints without having the type conversion, but they shouldn't. That just creates bugs.

It kind of looks like your going through robotc looking for things to complain about. I'm not sure if your just a young guy trying to prove your smarts or a forum troll. Either way, it's making me not want to help you.

Personally, I really like robotc, it's a great way to get people into robotics and a great way to program the NXT

You have to keep in mind that this is not running on a terminal, but on a unique system. Most other (maybe all other) versions of C for micro-controllers require that you program IO directly. That is that one has to program the micro-controllers io pins directly to access such things as LCD displays and sensors. I personally wouldn't care to write my own i2c asm code. RobotC makes all that stuff a breeze.


Mon Apr 07, 2008 11:15 am
Profile
Guru
User avatar

Joined: Sat Mar 01, 2008 12:52 pm
Posts: 1030
Post 
I didn't want to discuss with you about how you personally like RobotC or what errors may occur if variables exceed their allowed ranges.

all of the types
char (byte)
short
int
long
are integer, so they ought to be assigned and calculated to each other - actually this even seems to work with RobotC, but some calculations seem to cause runtime errors (e.g. modulo function: char_value%int_value or int_value%char_value).
And the editor function printf (RobotC equivalent: nxtDisplayTextLine) got a format string ("%d"), which enables the display of any integer variable of any size - why not of byte (char)?

I just asked if somebody may test the latter with one of the newer versions.

If you don't want to help me, let it be!

But this gives you not the right to offend me as a forum troll!!!

_________________
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)}


Mon Apr 07, 2008 12:54 pm
Profile
Rookie

Joined: Fri Apr 20, 2007 3:22 am
Posts: 36
Post 
Well Im sorry if I offended you.

However, you are in everybodies threads complaining about how robotc doesn't work the way that you would like it to work. Either it doesn't follow ansi standards to the letter or it's too complicated. I wonder why you're even using it. Most people would just not be using it if it was that much trouble to them. I'm not sure why you're here in the forums if it's not to troll.

Anyway. I apolgize to everyone else, I don't want to start a flame war here. There's enough noise already.


Mon Apr 07, 2008 2:29 pm
Profile
Guru
User avatar

Joined: Sat Mar 01, 2008 12:52 pm
Posts: 1030
Post 
ok, I take your apology, although I'm not sure if you're honest.

The reason why I "complain" that RobotC (as a commercial product featured by the Lego Company) in some (or many) cases doesn't work as it should is simply that it doesn't work as it should. The demands on a commercial software are higher than on freeware (such as NXC).

In Germany we got another (bigger) forum to discuss general programming problems and projects (in NXT-G, Robolab, MatLab, RobotC, NXC, NBC, Lejos, Java, NXJ, pbLua, NQC, for NXT, RCX, Scout,...), but here is the forum of the RobotC developers, here is the right place to point out to bugs of RobotC. Where else, if not here?

But I'm willing to stop this discussion too, let's return to the point of the opening question...

_________________
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)}


Mon Apr 07, 2008 4:33 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 8 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:  
cron



Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.