1 #include <stdio.h> 2 #include <string.h> 3 4 typedef volatile unsigned int vuint32_t; 5 6 struct 7 { 8 union 9 { 10 vuint32_t R ; 11 struct 12 { 13 vuint32_t : 23 ; 14 vuint32_t NVML : 1 ; 15 vuint32_t OPS : 2 ; 16 vuint32_t : 1 ; 17 vuint32_t OPR : 5 ; 18 } B ; 19 } CTRL ; 20 21 unsigned int age; 22 } Age = {0xff800000, 5}; 23 24 /* 25 000001ff 26 27 0xff800000 OK 28 */ 29 30 int main( ) 31 { 32 printf( "Sizeof( Age ) : %d\n", sizeof(Age) ); 33 34 printf( "Age.age : %d\n", Age.age); 35 36 printf( "Age.CTRL.B.NVML : %d\n", Age.CTRL.B.NVML); 37 printf( "Age.CTRL.B.OPS : %d\n", Age.CTRL.B.OPS); 38 printf( "Age.CTRL.B.OPR : %d\n", Age.CTRL.B.OPR); 39 40 return 0; 41 }
执行结果:
1 [hadoop@Master001 test_code]$ ./test.exe 2 Sizeof( Age ) : 8 3 Age.age : 5 4 Age.CTRL.B.NVML : 1 5 Age.CTRL.B.OPS : 3 6 Age.CTRL.B.OPR : 31
注意我们的机器上都是大端,也就是高位在后,低位在前的