Re: Why is "False" = "-1"?

From: Duane Bozarth (dp_bozarth_at_swko.dot.net)
Date: 07/25/04


Date: Sun, 25 Jul 2004 09:46:43 -0500

MikeD wrote:
>
> "Jonathan Wood" <jwood@softcircuits.com> wrote in message
> news:OTgT39ccEHA.3480@TK2MSFTNGP11.phx.gbl...
> >
> > > It's always been my understanding that 'If A Then' executes slightly
> > faster
> > > than 'If A = 1 Then' (or 'If A = -1 Then' or 'If A = True Then').
> >
> > This is not true. In both cases, A must be compared to zero or some other
> > value. The resulting code is the same.
>
> I don't quite understand your comment, at least as it relates to the point I
> was attempting to make.

No, he (we) understood exactly...the point is your contention is simply
wrong...

...snip babbling...
 
> The point I was making was that 'If A Then' executes slightly faster than
> 'If CBool(A) = True Then'. I guess I should have made that clearer. I can
> understand how my original post was confusing in this regard. Sorry about

<IF> the above contention <were> to be true (I've not taken the time to
actually look at the generated code), it would only be because of the
(unnecessary) cast that is written into the latter that VB perhaps would
not optimize out...

You would perhaps find it instructive to look at some of the details Dan
Barclay has in his article to which he posted a link...

In a nutshell, writing "If A Then" is <precisely> identical to writing
"If A<>0 Then" and will generate the same code and therefore the same
execution time. (Excepting perhaps for a <very> dumb compiler and I
believe Dan's article shows that the VB compiler isn't that
dumb--actually a couple of his examples show better code generation than
I had suspected). This is conclusion can be generalized to cover any
and all of the cases/pseudo-examples you've previously provided--they
all boil down to either an eq or ne and there has to be something for
the machine instruction to compare to--whether it's zero or nonzero
makes no difference.



Relevant Pages

  • Re: if statement
    ... The zero argument tells Matchto return the first *exact* match. ... > There can be 6 different numbers in the target evaluation cell and I want ... > compare it 6 different ways and if it matches the correct value compared ... > can't get it to string together more than the one comparison. ...
    (microsoft.public.excel.misc)
  • Re: writing a two hour movie script
    ... You're an idiot, appropriately named "Zero". ... includes TV movies and small companies. ... but to top it all off, you don't compare the number of aspiring ... agent in Florida on the Net who sold the book for him. ...
    (misc.writing)
  • Re: Well Ordering the Reals
    ... >>> If you do not specify the number of bits, then you don't know what number ... >>> number in order to compare it with another number. ... A TO-number starting with a zero and having infinitely many zeros ... So how does one tell, strictly from their representations, which is ...
    (sci.math)
  • Re: This calculation is just wrong / computer cant count!
    ... result is displayed on the screen (in an edit boxes) along with all the ... You cannot perform floating point math on a computer and compare the ... considered zero. ...
    (microsoft.public.vc.mfc)
  • Re: [PATCH] or51132.c: unaligned
    ... Perhaps better code generation? ... FWIW, I wonder how they really compare on misaligned and whether it would ... More majordomo info at http://vger.kernel.org/majordomo-info.html ...
    (Linux-Kernel)