これら 2 つの構造体定義が正常にコンパイルされるのはなぜですか。
struct foo {
int a;
} __attribute__((packed));
typedef struct __attribute__((packed)) {
int a;
} bar;
これは警告を出しますが:
typedef struct {
int a;
} baz __attribute__((packed));
warning: ‘packed’ attribute ignored [-Wattributes]
そして、これはエラーと警告を出します:
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]
初心者の C プログラマーとして、最後の 2 つの定義が機能しないという事実は、言語設計者/コンパイラー作成者のかなり恣意的な選択のように思えます。これには理由がありますか?gcc 4.7.3 を使用しています。