假设我们有以下结构定义:
typedef struct {
uint8_t a ;
} deepest_t ;
typedef struct {
deepest_t* deepest_ptr ;
} deeper_t ;
typedef struct {
deeper_t* deeper_ptr ;
} deep_t ;
typedef struct {
void* data ;
} data_container_t ;
和以下初始化:
deepest_t deepest = {
.a = 5,
} ;
deeper_t deeper = {
.deepest_ptr = &deepest,
} ;
deep_t deep = {
.deeper_ptr = &deeper,
} ;
现在的问题,您能否告诉我如何void* data
使用指定的初始化程序进行初始化,以便void* data
将deepest_t deepest
. 我试过这样的解决方案,但编译器尖叫它不是一个 const 值:
data_container_t data_container = {
.data = &(((deeper_t*) deep.deeper_ptr)->deepest_ptr),
} ;