Heh
Code:
a = a + b;
b = a - b;
a = a - b;
produces
movl -8(%ebp), %edx
leal -4(%ebp), %eax
addl %edx, (%eax)
movl -8(%ebp), %edx
movl -4(%ebp), %eax
subl %edx, %eax
movl %eax, -8(%ebp)
movl -8(%ebp), %edx
leal -4(%ebp), %eax
subl %edx, (%eax)
vs.
Code:
int temp = a;
a = b;
b = temp;
produces
movl -4(%ebp), %eax
movl %eax, -12(%ebp)
movl -8(%ebp), %eax
movl %eax, -4(%ebp)
movl -12(%ebp), %eax
movl %eax, -8(%ebp)
10 instructions vs. 6
and no undefined behaviour....
> Temp variable swap takes more time because of the temp variable creation
Creating 2 or 20 local variables takes the same amount of time, and since it's always done if you have any local variables at all (and takes only one instruction anyway), I fail to see your point.