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.


|