Solved

bool vs. BOOL

Posted on 1998-06-24
7
838 Views
Last Modified: 2012-06-21
Are bool (standard C++) and BOOL (defined in Visual C++) interchangable?
0
Comment
Question by:VEngineer
  • 4
  • 2
7 Comments
 
LVL 7

Accepted Solution

by:
galkin earned 10 total points
ID: 1166569
BOOL defined as int, it means 32 bit. bool is one bit. sometimes if you convert BOOL to bool you can get compiler warning
0
 
LVL 2

Author Comment

by:VEngineer
ID: 1166570
Is there a way I can redefine all BOOL to be bool so I can be consistent?
0
 
LVL 7

Expert Comment

by:galkin
ID: 1166571
#ifdef BOOL
#undef BOOL
#endif

#define BOOL bool
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 2

Author Comment

by:VEngineer
ID: 1166572
Is there a way I can redefine all BOOL to be bool so I can be consistent?
0
 
LVL 2

Author Comment

by:VEngineer
ID: 1166573
Oops, accidental repost.
0
 
LVL 2

Author Comment

by:VEngineer
ID: 1166574
I know 32 bit int is 4 bytes, but is bool a bit or a byte?  I always thought a byte was the lowest unit that could be addressed...
0
 
LVL 22

Expert Comment

by:nietod
ID: 1166575
The size of a bool is implimentation defined.  But it is pretty safe to say that it is at least a byte and ususally not more than the size of an int.  you can use sizeof(bool) to get the size of a bool for a particular implimentation.   For VC 5 it returns 1  meaning 1 byte not bit.  You don't want to redefine window's BOOLs to bool.  You could change things on "your side" that is, in your programs, but windows would still expect a 32 bit BOOL, not a 1 byte bool.  Also they have different logic.  A bool should specify only 0 or 1 in binary.  A BOOL can be and 32 bit binary value.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…

685 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question