Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Borland Delphi > Ouch, funny, na...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 3 Topic 3717 of 3852
Post > Topic >>

Ouch, funny, nasty bug: if Calculation and 7 > 0 then

by "Skybuck Flying" <BloodyShame@[EMAIL PROTECTED] > Apr 29, 2008 at 10:50 PM

Hello,

I was just inspecting/debugging my latest/newest video codec hehehehehe
and 
I encountered this line where I was trying to be smart and efficient and 
look what it brought me !

It brought me a bug, a very funny bug too, first I didn't see it, it took
a 
few seconds which I rare and then I realized what is going on:

First I let you play with this line for a few seconds, can you see what's 
the problem ?

if (vComponentsRemaining * 10 + vComponentsCompressed * 2) and 7 > 0 then
// 
mod 8

Ok I let you be for a few seconds, take a look again, until you absolutely

sure what the problem is.
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..

Ok,

Now I tell you what I think the problem is:

Delphi knows two kinds of "and"'s:

A logical "and"

and

A bitwise "and"

So Delphi is interpreting what I wrote wrongly.

How funny is that ?

It wouldn't have happened if I used mod or simply brackets.

Now I shall fix the code:

if ((vComponentsRemaining * 10 + vComponentsCompressed * 2) and 7) > 0
then 
// mod 8

See I LOVE BRACKETS, always use brackets is best !

I believe this is actually a small, little, but dangerous weakness in the 
Delphi language.

Maybe a little fix is better:

LogicAnd

BitwiseAnd

Yeah.

Oh well.

Bye,
  Skybuck.
 




 3 Posts in Topic:
Ouch, funny, nasty bug: if Calculation and 7 > 0 then
"Skybuck Flying"  2008-04-29 22:50:34 
Oh never mind, it seems to be working anyway.
"Skybuck Flying"  2008-04-29 22:57:00 
Re: Oh never mind, it seems to be working anyway.
"Skybuck Flying"  2008-04-29 23:04:59 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Fri Jul 25 19:33:57 CDT 2008.