Just an aside on the short-circuiting of conditionals... I remember getting
burnt by it back at uni (a few years ago now). I was doing something like:

if ( x && SomeFunction() )
{
        // do something
}
else
{
        // do something 2
}

In "do something 2" I was assuming that SomeFunction had been called - which
it won't if x is false. I remember scratching my head for ages on that
one...! :-)

Cheers,
Gavin.

-----Original Message-----
From: Peter Epstein [mailto:[EMAIL PROTECTED]]
Sent: Thursday, August 23, 2001 4:31 AM
To: Palm Developer Forum
Subject: RE: Question about code speed


I suggest disassembling the code and looking at the code generated by the
compiler. Nothing like looking at what the CPU actually gets!

I'm by no means a C expert, but if I recall correctly, C always short
circuits such things, applying the conditions in order from left to right,
and stopping as soon as the overall result of the if condition is known.
Therefore, your first sample will evaluate (y | 0x3f) first, while your
second sample will (obviously) evaluate (x) first. Switching around the
order of the arguments to the && operator, as you suggest, will cause (x) to
be evaluated first, and therefore should produce identical code to your
second sample.

Check the disassembly and see if I'm right. If you're using CodeWarrior, you
can disassemble any source file in the project by choosing Disassemble from
the Project menu. Another way to look at the assembly language code is with
PalmDebugger.
-- 
Peter Epstein

-- 
For information on using the Palm Developer Forums, or to unsubscribe,
please see http://www.palmos.com/dev/tech/support/forums/

-- 
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palmos.com/dev/tech/support/forums/

Reply via email to