|
Page 1 of 1
|
[ 13 posts ] |
|
Reading from boolean variables
Author |
Message |
oli_gould
Rookie
Joined: Tue Feb 26, 2008 4:41 pm Posts: 27
|
 Reading from boolean variables
I' ve noticed twice now that I'm unable to read boolean variables; It may be my code as I'm not experienced - or is it RobotC?
The code would be something like:
I know ofcourse I could use integers with 1 or 0 but sometimes it makes more sense to use booleans. Can anyone help please??
Thanks!
Oli
|
Fri Mar 28, 2008 2:53 pm |
|
 |
Ford Prefect
Guru
Joined: Sat Mar 01, 2008 12:52 pm Posts: 1030
|
what about
if (Flag)
instead of
if (Flag== true)

_________________ 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 3:07 pm |
|
 |
oli_gould
Rookie
Joined: Tue Feb 26, 2008 4:41 pm Posts: 27
|
yep! thanks Ford. what if I want to use the false aspect? Would that be..
if (!Flag)
{
}
much appreciated
|
Fri Mar 28, 2008 3:21 pm |
|
 |
Ford Prefect
Guru
Joined: Sat Mar 01, 2008 12:52 pm Posts: 1030
|
probably, yes.
But it's supposed to be a bug in RobotC, cause to standard C your code should work.
... developers... 
_________________ 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 3:24 pm |
|
 |
oli_gould
Rookie
Joined: Tue Feb 26, 2008 4:41 pm Posts: 27
|
I just tested it for others' benefit and yes !Flag does work.
|
Fri Mar 28, 2008 3:33 pm |
|
 |
Ford Prefect
Guru
Joined: Sat Mar 01, 2008 12:52 pm Posts: 1030
|
Fine !
Could you please report this bug to RobotC Bug Report?
http://www.education.rec.ri.cmu.edu/too ... n_page.php
_________________ 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 Apr 01, 2008 11:14 am |
|
 |
giannisAPI
Rookie
Joined: Sun Mar 02, 2008 9:41 am Posts: 25
|
why dont you just use a define int variable instead of boolean?
|
Sun Apr 13, 2008 8:13 pm |
|
 |
Ford Prefect
Guru
Joined: Sat Mar 01, 2008 12:52 pm Posts: 1030
|
why shouldn't bool be used?
_________________ 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 Apr 15, 2008 1:54 pm |
|
 |
giannisAPI
Rookie
Joined: Sun Mar 02, 2008 9:41 am Posts: 25
|
Traditional C language did not have a boolean data type..
But i dont see any reason why not to use it.. Probably in embedded systems applications (with memory constraints) is actually more sensible to use bool as they usually take less space in the memory (8 b) where int usually takes 16.
I was just saying that because u told something about a bug in RobotC thats why.
Regards,
giannis
|
Wed Apr 16, 2008 9:41 am |
|
 |
Ford Prefect
Guru
Joined: Sat Mar 01, 2008 12:52 pm Posts: 1030
|
OK, but
1) I didn't say that bool is ANSI, I just said that the code should work
2) if I wrote e.g.
(or however true and false may have been declared in RobotC) then
should work, or am I wrong?
_________________ 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 Wed Apr 16, 2008 3:10 pm, edited 1 time in total.
|
Wed Apr 16, 2008 10:59 am |
|
 |
giannisAPI
Rookie
Joined: Sun Mar 02, 2008 9:41 am Posts: 25
|
|
Wed Apr 16, 2008 11:16 am |
|
 |
Ford Prefect
Guru
Joined: Sat Mar 01, 2008 12:52 pm Posts: 1030
|
hi,
as I meanwhile found out, even boolean variables are standard ANSI C (C99):
http://de.wikipedia.org/wiki/Varianten_der_Programmiersprache_C
_________________ 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 Apr 26, 2008 4:35 am |
|
 |
Ford Prefect
Guru
Joined: Sat Mar 01, 2008 12:52 pm Posts: 1030
|
@developers:
can you confirm this bug?
_________________ 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 Apr 29, 2008 2:19 pm |
|
|
|
Page 1 of 1
|
[ 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
|
|