
Signature
Jonathan Wood
SoftCircuits Programming
http://www.softcircuits.com
> How about something like this:
> bool isTrue = (test != 0);
Yes, it seems that their is no implicit conversion of int to bool,
therefore the only recourse is to specifically use an equivalence
operator. Oh well, must have something to do with the overhead of the
JIT. Well, not that the JIT implicitly has overhead, it's just that we
have to specifically spoon feed it exactly we want.
Jon Skeet [C# MVP] - 22 Sep 2007 08:08 GMT
> > bool isTrue = (test != 0);
> Yes, it seems that their is no implicit conversion of int to bool,
> therefore the only recourse is to specifically use an equivalence
> operator. Oh well, must have something to do with the overhead of the
> JIT. Well, not that the JIT implicitly has overhead, it's just that we
> have to specifically spoon feed it exactly we want.
No, it's got nothing to do with JIT overhead - it's to do with program
correctness. An implicit conversion from int to bool could easily lead
to unintended consequences, such as:
int x;
if (x=3)
{
...
}
Conceptually an integer isn't true or false. Just because C and C++
have traditionally treated any non-zero value as "true" doesn't mean
it's a good idea.

Signature
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too