View unanswered posts | View active topics It is currently Thu May 24, 2018 9:39 pm

 Page 1 of 1 [ 13 posts ]
 Print view Previous topic | Next topic
Reading from boolean variables
Author Message
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:

 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
Guru

Joined: Sat Mar 01, 2008 12:52 pm
Posts: 1030

if (Flag)

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)

Fri Mar 28, 2008 3:07 pm
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
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)

Fri Mar 28, 2008 3:24 pm
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
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)

Tue Apr 01, 2008 11:14 am
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
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)

Tue Apr 15, 2008 1:54 pm
Rookie

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

 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
Guru

Joined: Sat Mar 01, 2008 12:52 pm
Posts: 1030

 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)

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
Rookie

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

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

Wed Apr 16, 2008 11:16 am
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):
 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)

Sat Apr 26, 2008 4:35 am
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)

Tue Apr 29, 2008 2:19 pm
Display posts from previous:  Sort by
 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 forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot post attachments in this forum

Search for:
 Jump to:  Select a forum ------------------ ROBOTC Applications    ROBOTC for LEGO MINDSTORMS       Third-party sensors    ROBOTC for CORTEX & PIC    ROBOTC for VEX IQ    ROBOTC for Arduino    Robot Virtual Worlds    Multi-Robot Communications    Issues and Bugs Competitions & Partners    Mini Urban Challenge    CS2N Robot Virtual Worlds Competitions       VEX Skyrise Competition 2014-2015       VEX Toss Up 2013-2014       FTC Block Party! 2013-2014    Competitions using VEX - BEST, TSA, VEX, and RoboFest!    FTC Programming    RoboCup Junior and Other ROBOT Competitions Virtual Brick Robotics Discussions    General Discussions    Project Discussions Off-Topic ROBOTC Forum & ROBOTC.net Suggestions/Feedback    ROBOTC Forums Suggestions/Comments    ROBOTC.net Suggestions/Comments       NXT Programming: Tips for Beginning with ROBOTC       VEX Programming: Tips for Beginning with ROBOTC    2013 Robotics Summer Of Learning       VEX Toss Up Programming Challenge       FTC Ring It Up! Programming Challenge    International Forums       Spanish Forums          ROBOTC for MINDSTORMS          ROBOTC for VEX       French Forums          ROBOTC pour Mindstorms          ROBOTC pour IFI VEX       Japanese Forums （日本語のフォーラム）       German Forums    2015 Spring Carnival Event    PLTW (Project Lead The Way)    Robotics Merit Badge    2014 Robotics Academy Summer of Learning

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