>void swap (int x, int y) { int tmp; tmp=x; x=y; y=tmp }

This isn't even correct. C passes arguments by value.

>#define swap(a,b) { a^=b;b^=a;a^=b }
>
>The second is from the book 'Applied Cryptography', which has some very
>tight code in it.  It avoids the funtion call altogether, it doesn't
>create any tempory variables, and should become 3 XOR commands in total
>once compiled. 

Except that a good compiler can probably beat the hell out of XOR
futzing if you define swap as an inline function.

Get it right, then make it fast.


-- 
SLUG - Sydney Linux User Group Mailing List - http://slug.org.au/
More Info: http://slug.org.au/lists/listinfo/slug

Reply via email to