is that some different of BOOL and bool? 
Author Message
 is that some different of BOOL and bool?

When I compile the code, VC.Net return a warning message,said a type
mismatch was happened.
I set a BOOL with bool.
When I look into the msdn,I know the BOOL is MFC type and bool is c++
type,But I don't know what's the different between them?

thanks!

james.fei



Fri, 07 Oct 2005 03:41:07 GMT  
 is that some different of BOOL and bool?
James,

Quote:
> When I compile the code, vc.net return a warning message,said a type
> mismatch was happened.
> I set a BOOL with bool.
> When I look into the msdn,I know the BOOL is MFC type and bool is c++
> type,But I don't know what's the different between them?

BOOL is just a typedef, mapping to a 4-byte integer. bool, otoh, is a native
C++ type, of 1-byte size.

P.S: BOOL is not really an MFC type, rather it is defined by the windows
headers.
--
Tomas Restrepo



Fri, 07 Oct 2005 04:04:00 GMT  
 is that some different of BOOL and bool?


Quote:

> > When I compile the code, vc.net return a warning message,said a type
> > mismatch was happened.
> > I set a BOOL with bool.
> > When I look into the msdn,I know the BOOL is MFC type and bool is c++
> > type,But I don't know what's the different between them?

> BOOL is just a typedef, mapping to a 4-byte integer. bool, otoh, is a native
> C++ type, of 1-byte size.

According to para 5.3.3.1, sizeof(bool) is specifically *not* required to be
1, although that is a common implementation choice (and the choice in VC++, at
least as of VC++ 2k3).

I can think of several good reasons to have sizeof(bool) == sizeof(int).  I
can also think of several good reasons for sizeof(bool) == 1.

What is certain, when used in a type safe manner, bool can only take on two
values (true and false).  BOOL can take on any integer value, not limited to
TRUE and FALSE.  If you're careful, that shouldn't happen, but with bool, it
*can't*.

Ken



Fri, 07 Oct 2005 04:59:49 GMT  
 is that some different of BOOL and bool?
Ken,

Quote:
> According to para 5.3.3.1, sizeof(bool) is specifically *not* required to
be
> 1, although that is a common implementation choice (and the choice in
VC++, at
> least as of VC++ 2k3).

Yes, I'm aware of this, but was pointing out the current VC++ definition. I
should've been more specific.

Thanks!
--
Tomas Restrepo



Fri, 07 Oct 2005 06:04:24 GMT  
 is that some different of BOOL and bool?
Thanks all answer my question.
Now I understand it,
If I just want to express the TRUE or FALSE, bool is the better choice.
But the BOOL is more flexible.


Quote:
> Ken,

> > According to para 5.3.3.1, sizeof(bool) is specifically *not* required
to
> be
> > 1, although that is a common implementation choice (and the choice in
> VC++, at
> > least as of VC++ 2k3).

> Yes, I'm aware of this, but was pointing out the current VC++ definition.
I
> should've been more specific.

> Thanks!
> --
> Tomas Restrepo




Sun, 09 Oct 2005 02:16:21 GMT  
 is that some different of BOOL and bool?

Quote:

> Thanks all answer my question.
> Now I understand it,
> If I just want to express the TRUE or FALSE, bool is the better choice.
> But the BOOL is more flexible.

You shouldn't be using either if you want to express something other
than true or false.  In the case of bool, you'll be prevented from
doing so, in the case of BOOL it's a misleading design but the compiler
won't stop you.

BOOL is useful when you need to work with the Windows API or some
wrapper thereof (MFC, ATL, WTL) that expects it.  In all other cases
where you need true or false, you should use bool.

--
Craig Powers
MVP - Visual C++



Sun, 09 Oct 2005 05:35:10 GMT  
 is that some different of BOOL and bool?
Now I really understand it,thanks all.


Quote:

> > Thanks all answer my question.
> > Now I understand it,
> > If I just want to express the TRUE or FALSE, bool is the better choice.
> > But the BOOL is more flexible.

> You shouldn't be using either if you want to express something other
> than true or false.  In the case of bool, you'll be prevented from
> doing so, in the case of BOOL it's a misleading design but the compiler
> won't stop you.

> BOOL is useful when you need to work with the Windows API or some
> wrapper thereof (MFC, ATL, WTL) that expects it.  In all other cases
> where you need true or false, you should use bool.

> --
> Craig Powers
> MVP - Visual C++



Mon, 10 Oct 2005 15:32:49 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. different between bool and BOOL, true and TRUE, false and FALSE

2. MIDL and BOOL vs bool

3. bool and BOOL

4. Difference between BOOL and bool

5. Newbie: BOOL vs bool

6. BOOL versus bool

7. Casting BOOL * to bool*

8. BOOL, boolean, bool ?

9. bool vs. BOOL

10. BOOL vs bool ??

11. bool vs BOOL

12. Why use BOOL versus native data type bool?

 

 
Powered by phpBB® Forum Software