:
This message was edited by AsmGuru62 at 2006-7-5 4:28:30
:
This message was edited by AsmGuru62 at 2006-7-5 4:25:46
: : : pretend that a and b are arguments to a function containing this
: : :
: : : int
: : : l=a,
: : : s=b;
: : : if(a<b){
: : : l=b;
: : : s=a;
: : : }
: : :
: : : /*alt*/
: : :
: : : int l,s;
: : : if(a>b){
: : : l=a;
: : : s=b;
: : : }
: : : else{
: : : l=b;
: : : s=a;
: : : }
: : :
: : : There is no difference between the two, only the former is more unclear about what the programmer expects, it seems that a is expected to be more and b, less, and the elimination of the else doesn't really matter, right?
: : :
: : : thats all.
: : : {2}rIng
: : :
: :
: :
: : The first version assigns values to the same variable twice, which looks messy imo. It is also less effective, so use the second version.
: :
:
Actually, the ELSE part of the IF() statement causes the additional JMP (forward) instruction, which is omitted if ELSE is not present. So, I will not be too quick to judge that one. Best bet is to assign (inside IF()) the values, which are the most frequent case in that piece of code.
:
: Jumps forward in code are not predicted by CPU and therefore should be used only when needed. I am nitpicking, of course, because the difference in execution time will be visible only on a VERY, VERY large loops.
:
:
Just moving two int (which can be 16 or 32 bit) to another memory location won't take long, but it is CPU dependant. On an 8-bit CPU it will take several instructions and therefore be slower than some additional jumps.
But since we are just talking about a few CPU ticks more or less, choose the version that is most readable/intuitive, which in this case is the if-else version.