Today ,I have learned the bit field feature of C Language in "The C Programming Language",so I search some exercise about bit field,and then I find the C Program source code below:
Code:
#include <stdio.h>
struct mybitfields
{
unsigned short a : 4;
unsigned short b : 5;
unsigned short c : 7;
}test;
int main(void)
{
int i = 0;
test.a = 2;
test.b = 3;
test.c = 0;
i = *((short *)&test);
printf("%d",i);
return 0;
}
After compile and run in X86,the result is 50!?I try to understand why,but I fail,so could some one tell me why and how get the result,thank you very much! ^@^
(compile environment Windows XP sp3,TDM-GCC 4.6.1,X86 architecture)