title: Compatible types and structures in C
body: <p>I have the following code:</p>
  
  <pre><code>int main(void)
  {
      struct { int x; } a, b;
      struct { int x; } c;
      struct { int x; } *p;
  
      b = a;   /* OK */
      c = a;   /* Doesn't work */
      p = &amp;a;  /* Doesn't work */
  
      return 0;
  }
  </code></pre>
  
  <p>which fails to compile under GCC (3.4.6), with the following error:</p>
  
  <pre><code>test.c:8: error: incompatible types in assignment
  test.c:9: warning: assignment from incompatible pointer type
  </code></pre>
  
  <p>Now, from what I understand (admittedly from the C99 standard), is that <code>a</code> and <code>c</code> should be compatible types, as they fulfill all the criteria in section 6.2.7, paragraph 1.  I've tried compiling with <code>std=c99</code>, to no avail.</p>
  
  <p>Presumably my interpretation of the standard is wrong?</p>
  
  <h2>Addendum</h2>
  
  <p>Incidentally, this question arises because I wanted to declare some template-like macros to wrap various datatypes without the overhead of having to declare named types/typedefs everywhere, e.g. a trivial example:</p>
  
  <pre><code>#define LINKED_LIST(T)   \
      struct {             \
          T    *pHead;     \
          T    *pTail;     \
      }
  
  ...
  
  LINKED_LIST(foo) list1;
  LINKED_LIST(foo) list2;
  
  ...
  
  LINKED_LIST(foo) *pList = &amp;list1;  /* Doesn't work */
  </code></pre>