内核中有写零长度数组,有时候看代码会迷糊,现在做个实验:
#include <stdio.h>
typedef struct my {
int a;
int b;
int c[0];
} my_ins;
void main()
{
my_ins *ins1 = malloc(sizeof(my_ins) + sizeof(my_ins));
my_ins *ins2 = ins1->c;
my_ins *ins3 = (my_ins*)((unsigned char*)(ins1) + sizeof(my_ins));
ins1->a = 0;
ins1->b = 2;
ins2->a = 45;
printf("my_ins size %d\n", sizeof(my_ins));
printf("ins2 0x%x, ins3 0x%x\