, , , @systemsfault, . , , . stackoverflow, , - , , . , ...
, , . -, , , (a1) (a2).
(b1) (b2) (a1) (a2). .
, :
#include <stdio.h>
#include <stdlib.h>
struct s_smallstruct{
int smallstruct;
};
struct s_test2{
struct s_smallstruct *smallstruct;
};
struct s_test1{
struct s_test2 *test2;
};
int main() {
int i, j, length = 2;
struct s_test1 *test1 = malloc( length * sizeof *test1 );
for (i=0; i<length; i++) {
test1[i].test2 = malloc( length * sizeof *test1[i].test2 );
for (j=0; j<length; j++) {
test1[i].test2[j].smallstruct = malloc( length * sizeof *test1[i].test2[j].smallstruct );
}
}
test1[1].test2[0].smallstruct[1].smallstruct = 123;
int num = test1[1].test2[0].smallstruct[1].smallstruct;
printf("num:%d\n", num);
return 0;
}