为什么这两个结构定义编译得很好:
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 程序员,最后两个定义不起作用的事实对于语言设计者/编译器编写者来说似乎是一个相当随意的选择。是否有一个原因?我正在使用 gcc 4.7.3。