c - Why don't people use xor swaps? -


i read on site using xor swaps fast because doesn't use temporary variable. here's example:

#include <stdio.h>  int main(void) {             int a=234,b=789;     b=b^a;     a=b^a;     b=b^a;     printf("a=%d,b=%d",a,b);     return 0; } 

why don't people use technique in real life code? poor style? there not defined it? optimisation compiler might produce more clear code, automatically?

  1. because readability preferred on performance.

  2. because tmp = a; = b; b = tmp; not that slow.

  3. because compiler optimize anyway.

  4. because works integers only. if want swap floating-point numbers? strings? custom objects? etc.


Comments

Popular posts from this blog

css - Text drops down with smaller window -

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

ruby on rails - Authlogic - how to make a registration and don't log in the new account? -