Re: weird /strange???
- From: "Heinz Ozwirk" <hozwirk.SPAM@xxxxxxxx>
- Date: Tue, 14 Mar 2006 23:03:00 +0100
"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. Even though bool is basically defined as enum { false, true } it is large enough to hold other values than 0 and 1. And sometimes such values are really created if casts are involved. The compiler will never do such things to you on its own, but there are always programmers, who triy to shoot themselves (or their co-workers) into their feet. So, to stay on the save side use
b = b1 != false;
to avoid such problems.
HTH
Heinz
.
- Follow-Ups:
- Re: weird /strange???
- From: Tim Slattery
- Re: weird /strange???
- References:
- weird /strange???
- From: kathy
- weird /strange???
- Prev by Date: List/Tree Control Hybrid
- Next by Date: Re: Derived controls in a dynamical dialog
- Previous by thread: weird /strange???
- Next by thread: Re: weird /strange???
- Index(es):
Relevant Pages
|