S
sinbad
chip_init.c
1 #include <stdio.h>
2 struct a {
3 char buf[0];
4 }b;
5 struct c {
6 char buf[1];
7 }d;
8
9 int main ()
10 {
11 printf("%u %u\n", sizeof(b), sizeof(d));
12 printf("%u %u", sizeof(struct a), sizeof(struct c));
13 return 0;
14 }
the output is
0 1
0 1
can someone explain why sizeof(b) and sizeof(struct a) is zero,
if there is no memory allocated how can i use this variable
and why gcc allows this.
thanks
~
1 #include <stdio.h>
2 struct a {
3 char buf[0];
4 }b;
5 struct c {
6 char buf[1];
7 }d;
8
9 int main ()
10 {
11 printf("%u %u\n", sizeof(b), sizeof(d));
12 printf("%u %u", sizeof(struct a), sizeof(struct c));
13 return 0;
14 }
the output is
0 1
0 1
can someone explain why sizeof(b) and sizeof(struct a) is zero,
if there is no memory allocated how can i use this variable
and why gcc allows this.
thanks
~