c - What is the meaning of a struct inside another without a tag name? -
i came across code snippet say:-
struct { int mem1; char mem2; struct { int inner_mem1; int inner_mem2; }; };
and found code snippet using inner struct's members directly using outer struct's variable name!!! ex:
struct *avar; .... avar->inner_mem1
is legal, code compiling , working fine!. purpose use in way? specific scenarios ?
please let me know thoughts.
this called "anonymous structure":
an unnamed member of structure type no tag called anonymous structure; unnamed member of union type no tag called anonymous union. members of anonymous structure or union considered members of containing structure or union. applies recursively if containing structure or union anonymous.
this not part of current c standard, c99, foreseen part of upcoming 1 (citation above). also, many compilers support feature extension.
Comments
Post a Comment