我在下面有一些结构定义:
typedef struct {
uint16_t a ;
} my_type1_t ;
typedef struct {
uint16_t b ;
} my_type2_t ;
typedef struct {
my_type1_t* a_ptr ;
my_type2_t* b_ptr ;
} both_t ;
typedef struct {
both_t* both_ptr ;
} gathered_t
以及上述结构的一些实例:
my_type1_t a = {
.a = 0x01U,
} ;
my_type2_t b = {
.b = 0xAAU,
} ;
我想问一下这是否可以在 C99 标准或更高版本中对结构进行一些初始化,如下所示:
gathered_t all = {
.both_ptr.a_ptr = &a,
.both_ptr.b_ptr = &b,
};
我知道这个问题的解决方案可以定义both_t结构的实例,但是这会引入额外的消耗内存的对象。