I noticed that there are several ways to define structures inside other structures in C:
struct s {
int abc;
struct {
int a;
};
struct {
int b;
} intern;
struct i {
int c;
};
struct i2 {
int d;
} intern2;
struct i3 {
int e;
};
struct i3 intern3;
};
This structure compiles using gcc or g ++, so I assume that all options are available in some way. I tried this as follows:
int main(int argc, char const *argv[])
{
struct s mystruct;
mystruct.abc = 0;
mystruct.a = 1;
mystruct.intern.b = 2;
mystruct.c = 3;
mystruct.intern2.d = 4;
mystruct.intern3.e = 5;
return 0;
}
Besides access mystruct.c, everything compiles (compilation error message βstruct sβ has no member named βcβ). Am I referring to structural parameters correctly? Are there any alternatives? How to access the parameter c?
source
share