I am trying to declare a structure that depends on a different structure. I want to use sizeof in order to be safe / pedantic.
typedef struct _parent { float calc ; char text[255] ; int used ; } parent_t ;
Now I want to declare a struct child_t that is the same size as parent_t.text .
How can i do this? (Pseudo-code below.)
typedef struct _child { char flag ; char text[sizeof(parent_t.text)] ; int used ; } child_t ;
I tried several different ways with parent_t and struct _parent , but my compiler does not accept.
As a trick, this seems to work:
parent_t* dummy ; typedef struct _child { char flag ; char text[sizeof(dummy->text)] ; int used ; } child_t ;
Is it possible to declare child_t without using dummy ?
c struct sizeof
kevinarpe Aug 24 2018-10-10T00: 00Z
source share