title: Macro SWAP(t,x,y) exchanging two arguments of type t
body: <p>So I am basically trying to make a SWAP(t,x,y) macro that exchanges two arguments of type t. I am trying to think of going around the problem when these two arguments are of the form </p>
  
  <p>v[i++] and w[f(x)] , i.e. SWAP(int, v[i++], w[f(x)]).</p>
  
  <p>The code below is basically crashing ...</p>
  
  <pre><code>#define SWAP(T,x,y) {T *p = x; T *q = y; T z = *p; *p = *q; *q = z;}
  
  int f (int x){
      return (0-x);
  }
  
  int main(void) {
  
  int v[] = {1,2,3};
  int i = 0;
  
  int w[] = {4,5,6};
  int x = -1;
  
  int *p = v;
  int *q = w;
  
  SWAP(int*, v[i++],w[f(x)]);
  
  return 0;
  }
  </code></pre>
  
  <p>Any ideas what may go wrong?</p>