title: Array pointer aliasing - undefined behavior?
body: <p>Does the following code invoke undefined behavior (due to aliasing violation or otherwise)?</p>
  
  <pre><code>int foo(int (*a)[10], int (*b)[5])
  {
      (*a)[5]++;
      return (*b)[0];
  }
  
  int x[10];
  foo(&amp;x, (int (*)[5])&amp;x[5]);
  </code></pre>
  
  <p>Note that the corresponding code using plain <code>int *</code> rather than pointer-to-array types would be perfectly legal, because <code>a</code> and <code>b</code> would be pointers to the same type and thus allowed to alias one another.</p>
  
  <p><strong>Edit:</strong> The interesting consequence, if this is in fact an aliasing violation, is that it seems to be a hackish but valid way to get <code>restrict</code> semantics pre-C99. As in:</p>
  
  <pre><code>void some_func(int *aa, int *bb)
  {
      int (*a)[1] = (void *)aa;
      int (*b)[2] = (void *)bb;
      /* Now **a and **b can be assumed by the compiler not to alias */
  }
  </code></pre>
  
  <p>Presumably if you needed to access an actual array at each address, you could use SIZE_MAX-1 and SIZE_MAX-2 etc. as the differing sizes.</p>