Re: weird /strange???



One more thing:

Why would you do (true && b1)? Wouldn't that be the same as

b = b1 since "true" would always be a positive result? You don't really
"need" to compare it to "true".

Tom

bool b,b1;
b1 = MyData.success;
//MyData is protected using Mutex, b1=true here by using Visual Studio
watch window
b = (b1 == true);//return false ??????
b = (true && b1);//return true

"Tim Slattery" <Slattery_T@xxxxxxx> wrote in message
news:g56g12ts8qu4o0lvo4m4rd0rpubaelu5kg@xxxxxxxxxx
"Heinz Ozwirk" <hozwirk.SPAM@xxxxxxxx> wrote:

"kathy" <yqin_99@xxxxxxxxx> schrieb im Newsbeitrag
news:1142359707.474751.38170@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
I have a piece of code which is in a multithread program:

...
bool b,b1;
b1 = MyData.success;
//MyData is protected using Mutex, b1=true here by using Visual Studio
watch window
b = (b1 == true);//return false ??????
b = (true && b1);//return true
...

Never compare a boolean value with true, always compare with false.

Why in the world?!?!?

Even though bool is basically defined as enum { false, true } it is large
enough to hold other values than 0 and 1.

No. The older Windows typedef BOOL is a redefinition of an integer,
and many different values could be stored there. The C++ primitive
datatype "bool", on the other hand, can store only the constants true
or false.

--
Tim Slattery
MS MVP(DTS)
Slattery_T@xxxxxxx


.



Relevant Pages

  • Re: weird /strange???
    ... Never compare a boolean value with true, ... The older Windows typedef BOOL is a redefinition of an integer, ...
    (microsoft.public.vc.mfc)
  • weird /strange???
    ... I have a piece of code which is in a multithread program: ... bool b,b1; ... //MyData is protected using Mutex, b1=true here by using Visual Studio ...
    (microsoft.public.vc.mfc)
  • NamedMutex with SECURITY_ATTRIBUTES
    ... service is able to create the mutex but my user app gets ... > private bool InternalReleaseMutex() ... > private static extern bool ReleaseMutex(IntPtr ... > public uint Owner; ...
    (microsoft.public.dotnet.framework.interop)
  • Re: why UI gets hangs
    ... It isn't a semaphore; ... The wiki author calls it a 'binary semaphore', better known as a mutex. ... It is a bool variable, and as such, it's just dumb data. ... don't necessarily share a completely consistent view of memory. ...
    (microsoft.public.vc.mfc)
  • Re: [PATCH 7/7] [RFC] APM emulation driver for class batteries
    ... Utterly unsafe. ... APM interface needs a mutex. ... Just mark it bool, when you fix it with mutex, you can go back to ... tristate. ...
    (Linux-Kernel)