I saw this way to implement some kind of struct
inheritance with anonymous struct
in C11, and wanted to try it out. Here is what I have:
struct struct_a {
int aa;
};
struct struct_b {
struct struct_a;
int bb;
};
int main(void)
{
volatile struct struct_b my_b;
my_b.aa = 5; /* not a member of my_b */
my_b.bb = 6;
}
Result from gcc:
$ gcc -std=c11 struct_extend.c
struct_extend.c:11:20: warning: declaration does not declare anything
struct struct_a;
^
struct_extend.c: In function ‘main’:
struct_extend.c:18:9: error: ‘volatile struct struct_b’ has no member named ‘aa’
my_b.aa = 5; /* not a member of my_b */
Relevant:
$ gcc --version
gcc (Debian 6.3.0-18) 6.3.0 20170516
Is this not implemented in my compiler, or am I doing it wrong?