> Is there any difference in the speed at which the code 
> completes if x is
> false?  Will it change if the first line in sample one reads :
> if(x && (y | 0x3f) )
> 

I learned that "sample one" basically evaluates to "sample two", so they are
equivalent, from a time standpoint.  I haven't run this in a profiler though
 . .

Hmmm, looking further at your message, basically my understanding is that
the compiler will break the if statement w/ the "&" into two if statements
and evalutate the second only if the first is true.  In your case if the
first item is false, it doesn't matter if the second is true or false; the
if statement will fail.  So if you know that one of the conditions will be
false most of the time, evaluate it first and you will come out ahead in the
long run.  

All things considered, unless you're running this code a _lot_ it really
doesn't make a significant difference.

Cheers,

-DGA

> This is kind of a generic question, but I don't have enough 
> knowledge of the
> inner workings of compilers to know the answer.
> 
> Given these two code snippets:
> 
> // begin sample one
> if((y | 0x3f) && x)
> {
>     //do something
> }
> else
> {
>     //do something else
> }
> // end sample one
> 
> // begin sample two
> if(x)
> {
>     if(y | 0x3f)
>     {
>         // do something
>     }
> }
> else
> {
>     // do something else
> }
> // end sample two
> 
> Unfortunately, my program wont run in the emulator so I cannot run the
> profiler on the code...
> 
> Thanks,
> Mike
> 
> 
> 
> -- 
> 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