/* 0长度数组 */
typedef struct s_struct {
uint8_t len;
uint8_t buff[0]; /* 定义时没有分配长度 */
}s_struct;
s_struct *test = (s_struct *)malloc(sizeof(s_struct) + 100);
if (test != NULL) {
test.len = 100;
}
/* 可变长度数组 */
uint8_t test_func(uint8_t len)
{
uint8_t buff[len];
memset(buff, 0, sizeof(buff));
return 0;
}
typedef struct s_struct {
uint8_t len;
uint8_t buff[0]; /* 定义时没有分配长度 */
}s_struct;
s_struct *test = (s_struct *)malloc(sizeof(s_struct) + 100);
if (test != NULL) {
test.len = 100;
}
/* 可变长度数组 */
uint8_t test_func(uint8_t len)
{
uint8_t buff[len];
memset(buff, 0, sizeof(buff));
return 0;
}