ROBOTC.net forums
http://robotc.net/forums/

Reading from boolean variables
http://robotc.net/forums/viewtopic.php?f=1&t=490
Page 1 of 1

Author:  oli_gould [ Fri Mar 28, 2008 2:53 pm ]
Post subject:  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

Author:  Ford Prefect [ Fri Mar 28, 2008 3:07 pm ]
Post subject: 

what about

if (Flag)

instead of

if (Flag== true)

:?:

Author:  oli_gould [ Fri Mar 28, 2008 3:21 pm ]
Post subject: 

yep! thanks Ford. what if I want to use the false aspect? Would that be..

if (!Flag)
{
}

much appreciated

Author:  Ford Prefect [ Fri Mar 28, 2008 3:24 pm ]
Post subject: 

probably, yes.

But it's supposed to be a bug in RobotC, cause to standard C your code should work.


... developers... :!: :?:

Author:  oli_gould [ Fri Mar 28, 2008 3:33 pm ]
Post subject: 

I just tested it for others' benefit and yes !Flag does work.

Author:  Ford Prefect [ Tue Apr 01, 2008 11:14 am ]
Post subject: 

Fine !
Could you please report this bug to RobotC Bug Report?
http://www.education.rec.ri.cmu.edu/too ... n_page.php

Author:  giannisAPI [ Sun Apr 13, 2008 8:13 pm ]
Post subject: 

why dont you just use a define int variable instead of boolean?

Author:  Ford Prefect [ Tue Apr 15, 2008 1:54 pm ]
Post subject: 

why shouldn't bool be used?

Author:  giannisAPI [ Wed Apr 16, 2008 9:41 am ]
Post subject: 

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

Author:  Ford Prefect [ Wed Apr 16, 2008 10:59 am ]
Post subject: 

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?

Author:  giannisAPI [ Wed Apr 16, 2008 11:16 am ]
Post subject: 

:lol: :lol: :lol: :lol:


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

Author:  Ford Prefect [ Sat Apr 26, 2008 4:35 am ]
Post subject: 

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

Author:  Ford Prefect [ Tue Apr 29, 2008 2:19 pm ]
Post subject: 

@developers:
can you confirm this bug?

Page 1 of 1 All times are UTC - 5 hours [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/