c - How to initialize void* data struct member with another struct member in C99? -
let's assume have below struct definitions:
typedef struct { uint8_t ; } 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 ;
and following initializations:
deepest_t deepest = { .a = 5, } ; deeper_t deeper = { .deepest_ptr = &deepest, } ; deep_t deep = { .deeper_ptr = &deeper, } ;
and question, please tell me how initialize void* data
usage of designated initializer in order void* data
point deepest_t deepest
. i've tried such solution, compiler screaming not const value :
data_container_t data_container = { .data = &(((deeper_t*) deep.deeper_ptr)->deepest_ptr), } ;
in here believe keeping address of deepest_ptr
..
data_container_t data_container = { .data = &(((deeper_t*) deep.deeper_ptr)->deepest_ptr), } ;
so retrieve it, can ..
deepest_t * d = *((deepest_t**)(data_container.data)); printf(" %ud \n", (*d).a);
since can't use void*
until cast ..
here's live execution