title: Why do these C struct definitions give warnings and errors?
body: <p>Why do these two struct definitions compile fine:</p>
  
  <pre><code>struct foo {
      int a;
  } __attribute__((packed));
  
  typedef struct __attribute__((packed)) {
      int a;
  } bar;
  </code></pre>
  
  <p>While this one gives a warning:</p>
  
  <pre><code>typedef struct {
      int a;
  } baz __attribute__((packed));
  
  
  warning: ‘packed’ attribute ignored [-Wattributes]
  </code></pre>
  
  <p>And this one gives an error and a warning:</p>
  
  <pre><code>typedef struct qux __attribute__((packed)) {
      int a;
  } qux;
  
  error: expected identifier or ‘(’ before ‘{’ token
  warning: data definition has no type or storage class [enabled by default]
  </code></pre>
  
  <p>As a novice C programmer, the fact that the last two definitions don't work seems like a fairly arbitrary choice on the parts of the language designers/compiler writers. Is there a reason for this? I'm using gcc 4.7.3.</p>