View unanswered posts | View active topics It is currently Tue Nov 25, 2014 5:28 pm






Reply to topic  [ 13 posts ] 
Reading from boolean variables 
Author Message
Rookie

Joined: Tue Feb 26, 2008 4:41 pm
Posts: 27
Post 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:

Code:
bool Flag;

task main ()
{

if (//something)
{
Flag = true
}

if (Flag == true)                 //this isn't working!!
{
// do something
}
}


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
Profile
Guru
User avatar

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

Joined: Tue Feb 26, 2008 4:41 pm
Posts: 27
Post 
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
Profile
Guru
User avatar

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

Joined: Tue Feb 26, 2008 4:41 pm
Posts: 27
Post 
I just tested it for others' benefit and yes !Flag does work.


Fri Mar 28, 2008 3:33 pm
Profile
Guru
User avatar

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

Joined: Sun Mar 02, 2008 9:41 am
Posts: 25
Post 
why dont you just use a define int variable instead of boolean?


Sun Apr 13, 2008 8:13 pm
Profile
Guru
User avatar

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

Joined: Sun Mar 02, 2008 9:41 am
Posts: 25
Post 
Ford Prefect wrote:
why shouldn't bool be used?


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
Profile
Guru
User avatar

Joined: Sat Mar 01, 2008 12:52 pm
Posts: 1030
Post 
giannisAPI wrote:
Traditional C language did not have a boolean data type..


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.
Code:
#define false 0
#define true  1

(or however true and false may have been declared in RobotC)
then
Code:
if (b_value == 1 )
// and
if ( b_value == true)
// and
if ( b_value != false)


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
Profile
Rookie

Joined: Sun Mar 02, 2008 9:41 am
Posts: 25
Post 
:lol: :lol: :lol: :lol:


yes it should work mate you are right....


Wed Apr 16, 2008 11:16 am
Profile
Guru
User avatar

Joined: Sat Mar 01, 2008 12:52 pm
Posts: 1030
Post 
hi,
as I meanwhile found out, even boolean variables are standard ANSI C (C99):
Quote:
... 1999 neuer ISO-Standard ISO/IEC 9899:1999, auch als C99 bezeichnet, hervor. C99 löst den Standard ISO/IEC 9899:1990 (C90) ab.

Zu diesem Standard ist 2001 ein Technical Corrigendum (TC) TC1 erschienen. Dieses Dokument TC1 ist frei verfügbar. Ein weiteres Korrigendum wurde 2004 als Technical Corrigendum 2 veröffentlicht (TC2).

Mit C99 flossen einige aus C++ bekannte Erweiterungen in die Sprache C ein.

Zu den wichtigsten Neuerungen gehören:

Zulassen des aus C++ bekannten Zeilenkommentars „//“
Datentypen long long int und unsigned long long int, die mindestens 64 Bit groß sein müssen; boolescher Datentyp _Bool; Datentyp _Complex zur Behandlung komplexer Zahlen
Ganzzahlige Datentypen mit vorgegebener Mindestbreite (1, 2, 4 oder 8 Byte)
Alias-freie Zeiger (Schlüsselwort restrict)
Lokale Felder variabler Größe
Frei platzierbare Deklaration von Bezeichnern (in C90 durften diese nur am Anfang eines Blocks stehen)
Inline-Funktionen
Verbot des „impliziten int“; Verbot impliziter Funktionsdeklarationen
Alternative Schreibweisen für Operatoren, wie beispielsweise and anstelle von &&
hexadezimale Gleitkommakonstanten. Ein- und Ausgabe in scanf() und printf() über „%a“ und „%A“
Präprozessor-Makros mit variabler Parameteranzahl
Erweiterte Bibliothek (z.B. complex.h: csin(), math.h: sinf() sinf() erf() tgamma())
(Quelle: Wikipedia)

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
Profile
Guru
User avatar

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