Go to Post it's flattering, but a little scary, because I don't know if I'm ready to be an inspiration! - MissInformation [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Closed Thread
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 20-12-2004, 08:13
atmaturen atmaturen is offline
Registered User
#0703
 
Join Date: Dec 2004
Location: Saginaw, Michigan
Posts: 8
atmaturen is an unknown quantity at this point
Send a message via AIM to atmaturen
Question boolean

ello all,
i've seen to have forgotten how to declare a boolean variable...
any help would be greatly appriceated.
thanks in advanced.
(wow, my spelling is vile)
  #2   Spotlight this post!  
Unread 20-12-2004, 09:25
Joe Ross's Avatar Unsung FIRST Hero
Joe Ross Joe Ross is offline
Registered User
FRC #0330 (Beachbots)
Team Role: Engineer
 
Join Date: Jun 2001
Rookie Year: 1997
Location: Los Angeles, CA
Posts: 8,599
Joe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond repute
Re: boolean

There is no boolean variable type in C. Most people declare it as char (or unsigned char) and use the value 0 for false and 1 (or any value != 0) for true.

Through the use of #defines and typedefs, you can emulate it, though.

Code:
typedef unsigned char bool
#define TRUE 1
#define FALSE 0
Then just use the variable type bool and the values TRUE and FALSE.
  #3   Spotlight this post!  
Unread 20-12-2004, 09:26
Mark McLeod's Avatar
Mark McLeod Mark McLeod is offline
Just Itinerant
AKA: Hey dad...Father...MARK
FRC #0358 (Robotic Eagles)
Team Role: Engineer
 
Join Date: Mar 2003
Rookie Year: 2002
Location: Hauppauge, Long Island, NY
Posts: 8,904
Mark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond repute
Re: boolean

Quote:
Originally Posted by atmaturen
i've seen to have forgotten how to declare a boolean variable...
There isn't an explicit boolean type.
Typically, you use "char"
__________________
"Rationality is our distinguishing characteristic - it's what sets us apart from the beasts." - Aristotle
  #4   Spotlight this post!  
Unread 20-12-2004, 17:40
atmaturen atmaturen is offline
Registered User
#0703
 
Join Date: Dec 2004
Location: Saginaw, Michigan
Posts: 8
atmaturen is an unknown quantity at this point
Send a message via AIM to atmaturen
Re: boolean

do the boolean functions (and & not) work this way?
  #5   Spotlight this post!  
Unread 20-12-2004, 17:48
colt527 colt527 is offline
Registered User
AKA: Ken Colton
FRC #0527
Team Role: Mentor
 
Join Date: Feb 2004
Rookie Year: 2002
Location: Long Island
Posts: 123
colt527 is a splendid one to beholdcolt527 is a splendid one to beholdcolt527 is a splendid one to beholdcolt527 is a splendid one to beholdcolt527 is a splendid one to beholdcolt527 is a splendid one to beholdcolt527 is a splendid one to behold
Send a message via AIM to colt527
Re: boolean

I'm not 100% sure if this wouldn't work, but my original thought would be it wouldn't.

char boolVar = 1;

if(boolVar)
{
//Do this
}


but for && and || and != they all work the same:

char var1 = 1;
char var2 = 0;

if(var1 == 1 && var2 != 1)
{
//do this
}
__________________
Mentor, Team 527 -- Plainedge Red Dragons
FIRST Volunteer
SUNY Stony Brook Computer Science 2010
kcolton@gmail.com
  #6   Spotlight this post!  
Unread 20-12-2004, 17:52
Unsung FIRST Hero
Mike Betts Mike Betts is offline
Electrical Engineer
no team
Team Role: Engineer
 
Join Date: Dec 2001
Rookie Year: 1995
Location: Homosassa, FL
Posts: 1,442
Mike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond repute
Re: boolean

Quote:
Originally Posted by atmaturen
do the boolean functions (and & not) work this way?
Use this (http://www.lysator.liu.se/c/bwk-tutor.html) as a reference and you should be OK.
__________________
Mike Betts

Alumnus, Team 3518, Panthrobots, 2011
Alumnus, Team 177, Bobcat Robotics, 1995 - 2010
LRI, Connecticut Regional, 2007-2010
LRI, WPI Regional, 2009 - 2010
RI, South Florida Regional, 2012 - 2013

As easy as 355/113...
  #7   Spotlight this post!  
Unread 21-12-2004, 17:56
Astronouth7303's Avatar
Astronouth7303 Astronouth7303 is offline
Why did I come back?
AKA: Jamie Bliss
FRC #4967 (That ONE Team)
Team Role: Mentor
 
Join Date: Jan 2004
Rookie Year: 2004
Location: Grand Rapids, MI
Posts: 2,071
Astronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud of
Re: boolean

In reply to previous concerns:
As long as you use the logical operators (&& || !) instead of the bitwise ones (& | ~ ^), you shold be ok.

If you need to use == and !=, I would recomend using one of this macros around the operands (the values being compared).
Code:
// CBOOL Converts to BOOLean
#define CBOOL(val) ((val) ? TRUE : FALSE)
// LOGically EQuivalent
#define LOG_EQ(val1,val2) (CBOOL(val1) == CBOOL(val2))
// LOGically Not EQuivalent
#define LOG_NEQ(val1,val2) (CBOOL(val1) != CBOOL(val2))
  #8   Spotlight this post!  
Unread 28-12-2004, 00:28
jude's Avatar
jude jude is offline
Registered User
#0116 (Epsilon Delta)
Team Role: Mentor
 
Join Date: Dec 2004
Rookie Year: 2004
Location: Herndon, Virginia
Posts: 3
jude is on a distinguished road
Send a message via AIM to jude
Re: boolean

You can get rid of the #defines by using an enum:
Code:
typedef enum {TRUE=1, FALSE=0} bool;
There's also a small practical benefit for this approach:

Some compilers will be able to do some extra type-checking against the enum values, and warn you if you accidentily try to do something like "bool b_Var = 5".


Quote:
Originally Posted by Joe Ross
There is no boolean variable type in C. Most people declare it as char (or unsigned char) and use the value 0 for false and 1 (or any value != 0) for true.

Through the use of #defines and typedefs, you can emulate it, though.

Code:
typedef unsigned char bool
#define TRUE 1
#define FALSE 0
Then just use the variable type bool and the values TRUE and FALSE.
  #9   Spotlight this post!  
Unread 28-12-2004, 12:49
Raven_Writer's Avatar
Raven_Writer Raven_Writer is offline
2004 Detroit & Pittsburgh Winners
AKA: Eric Hansen
FRC #0005 (RoboCards)
Team Role: Mentor
 
Join Date: Jan 2003
Rookie Year: 2002
Location: Melvindale
Posts: 1,549
Raven_Writer is just really niceRaven_Writer is just really niceRaven_Writer is just really niceRaven_Writer is just really niceRaven_Writer is just really nice
Send a message via ICQ to Raven_Writer Send a message via AIM to Raven_Writer Send a message via MSN to Raven_Writer Send a message via Yahoo to Raven_Writer
Re: boolean

Assuming you're using MPLAB/CBOT, I think the #define method would be best. The method to use though is completely based on what makes you happy.

There's honestly countless number of ways to accomplish though. Like I said though, I think the #define method is best *not to mention, very short on the lines side*
__________________
AIM: wisprmylastbreth
EMail: nightskywriter@gmail.com
Y!: synsoflife

"ai yoru ga" -- "Love the nights"
Closed Thread


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Boolean statement blindguyinanorg Programming 2 15-02-2004 07:31


All times are GMT -5. The time now is 18:26.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi