Possible Duplicate:
Practical Use of Zero-Length Bitfields
Why some structures have zero-width bit fields, and why is it required?
struct foo {
int a:3;
int b:2;
int :0; // Force alignment to next boundary.
int c:4;
int d:3;
};
int main()
{
int i = 0xFFFF;
struct foo *f = (struct foo *)&i;
printf("a=%d\nb=%d\nc=%d\nd=%d\n", f->a, f->b, f->c, f->d);
return 0;
}
The output of above program is
manav@os-team:~/programs/test$ ./a.out
a=-1
b=-1
c=-8
d=0
Please explain why these values are negative, and the memory layout of these variables inside the structure?