Solved

bool vs. BOOL

Posted on 1998-06-24
7
833 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
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
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

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to copy an image file into clipboard C/C++? 1 199
C++ to C# code conversion issue 4 112
Create a path if not exists 7 90
FMX TCameraComponent Problem 2 86
Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

831 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