结构成员的有无,编译时就定下了。不过
如果是要实现结构长度可变,可以使用零长度数组
struct A { UINT8 c; UINT8 e; UINT16 f; UINT8 g; UINT8 d[0]; //结构最后一个成员设为零长度数组 }; UINT8 b; struct A * test_p;
if (b&0x08 == 0x08) test_p=malloc(sizeof(struct A) + 1); //1可以改为任意 else test_p=malloc(sizeof(struct A)) ;
|
|