c - Initializing an array member of a struct by name -
i have struct looks this:
typedef struct { uint32_t a; uint32_t b; uint32_t c[5]; uint32_t d; } my_struct_t;
i want initialize c
, name, non-zero value. want else 0.
if c
not array, do:
static my_struct_t my_struct = {.b = 1};
and know can this:
static my_struct_t my_struct = {.c[0]=5, .c[1]=5, .c[2]=5, .c[3]=5, .c[4]=5};
but wondering if there more elegant syntax of unaware: like:
static my_struct_t my_struct = {.c[] = {5,5,5,5,5}};
i have read following, don't answer question:
initializing struct 0
initialize/reset struct zero/null
a better way initialize static array member of class in c++ ( const preferred though )
how initialize members of array same value?
so wrote question , experimented while , found following work:
static my_struct_t my_struct = {.c={5,5,5,5,5}};
Comments
Post a Comment