C语言 结构体的变长数组

1.
`typedef struct
{

int a[];

}CLASS_B;`
结果:
error: flexible array member in otherwise empty struct
结构不能只有变长数组一项

2.
`typedef struct
{

int a[];
int b[];

}CLASS_B;`
结果:
error: flexible array member not at end of struct
变长数组在结构体内只能有一项且位于最后一项,改为以下则通过~~~~
`typedef struct
{

int *a;
int b[];

}CLASS_B;`
3.
typedef struct
{

int *a;
int b[];

}CLASS_B;
typedef struct
{

CLASS_B a;
CLASS_B b;
int *c;

}CLASS;
结果:
编译通过

评论

暂无评论