Re: weird /strange???



"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
.



Relevant Pages

  • Visual Studio 2003, Watch Window, ListView, SubItems
    ... explore the collection via the Watch Window in Visual Studio .NET 2003. ... My textbook was written for the previous version of Visual Studio and ... this feature gone away? ...
    (microsoft.public.dotnet.languages.vb)
  • Re: weird /strange???
    ... //MyData is protected using Mutex, b1=true here by using Visual Studio ... Never compare a boolean value with true, ... The older Windows typedef BOOL is a redefinition of an integer, ...
    (microsoft.public.vc.mfc)
  • Re: already running
    ... renaming it. ... If you need to avoid that possibility research on MUTEX, ... So if you have an App that takes a bit of time on ...
    (microsoft.public.vb.general.discussion)
  • Re: Windbg or SoftIce?
    ... hovering the mouse over a variable should display its value in a ... >>> tool tip just like visual studio ... variable is located (for example, we would see it in the watch window), ... Spiro R. Trikaliotis ...
    (microsoft.public.development.device.drivers)
  • Re: beginning with ML
    ... other languages have managed to avoid? ... So you want monochrome teletype when you could have a hardware-accelerated ... with Visual Studio and Mathematica. ...
    (comp.lang.functional)