Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Analyzing ReactOS's code

Name: Anonymous 2011-09-05 14:37

I will only cite the following piece of code for dessert:

    #define SWAP(a,b,c)  c = a;\
                         a = b;\
                         a = c

http://www.viva64.com/en/a/0076/

Name: Anonymous 2011-09-06 3:25

>>1
What's wrong with:

inline void Swap(int *a, int *b)
{
    a ^= b;
    b ^= a;
    a ^= b;
}

Name: Anonymous 2011-09-06 8:30

>>7

xor swap fails if you happen to call it with two pointers to the same address, so it might be good to have


inline void swap(int *a, int *b) {
  if(a != b) {
    *a ^= *b;
    *b ^= *a;
    *a ^= *b;
  }
}


although the check will have a certain amount of cost, and a smart program shouldn't try to swap the contents of a single memory address.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List