【发布时间】:2014-02-05 23:29:21
【问题描述】:
我们可以像下面那样做 struct hack(使用 int 类型)
struct node{
int i;
struct node *next;
int p[0];
}
int main(){
struct node *n = // is this the correct hack i.e. p[10]?
malloc(sizeof(struct node) + sizeof(int) * 10);
}
同样使用大小为 1 的 int 类型
struct node{
int i;
struct node *next;
int p[1];
}
int main(){
struct node *n = // is this a correct hack i.e. p[10]?
malloc(sizeof(struct node) + sizeof(int) * 10);
}
【问题讨论】: