Re: bool implementation
From: Doug Harrison [MVP] (dsh_at_mvps.org)
Date: 01/15/05
- Next message: Doug Harrison [MVP]: "Re: Crash by allocationg small blocks"
- Previous message: Walter Briscoe: "Re: Crash by allocationg small blocks"
- In reply to: Mark Randall: "Re: bool implementation"
- Next in thread: Carl Daniel [VC++ MVP]: "Re: bool implementation"
- Messages sorted by: [ date ] [ thread ]
Date: Sat, 15 Jan 2005 07:00:14 -0600
Mark Randall wrote:
>Might as well use char or unsigned char, both evaluate likewise to true,
There are big differences between those types and bool. Conversion from
non-bool to bool essentially goes like this:
// x is bool, y is non-bool integral type or pointer
x = y != 0; // What you really get when you say x = y;
Besides working for pointers, bool does the right thing for wider types. For
example:
unsigned x = 0x100;
unsigned char y = x;
bool z = x;
Now, x is considered "true" for all values != 0. Assuming VC's data types, y
is false for all values of x >= 0x100. However, z is true whenever x is
"true".
>small performance hit tho.
Using a bool can indeed result in a small performance hit when assigning
values of types other than bool to it, due to the conversion performed.
-- Doug Harrison Microsoft MVP - Visual C++
- Next message: Doug Harrison [MVP]: "Re: Crash by allocationg small blocks"
- Previous message: Walter Briscoe: "Re: Crash by allocationg small blocks"
- In reply to: Mark Randall: "Re: bool implementation"
- Next in thread: Carl Daniel [VC++ MVP]: "Re: bool implementation"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|