1 #include <stdio.h>
2
3
4 struct test {
5 char c;
6 int i;
7 double d;
8 void *p;
9 int a[0];
10 };
11
12 int main (void) {
13 struct test t;
14 printf("size of struct is: %d\n", sizeof(t));
15 return 0;
16 }
出力:
size of struct is: 20
なぜint a[0]
考慮されないのですか?
私は試した:
1 #include <stdio.h>
2
3
4 struct test {
5 int a[0];
6 };
7
8 int main (void) {
9 struct test t;
10 printf("size of struct is: %d\n", sizeof(t));
11 return 0;
12 }
そして出力:
size of struct is: 0
a[0]
構造体のメンバーです。では、なぜ構造の大きさに考慮されていないのでしょうか。