#include <stdio.h> typedef union { unsigned long dwVal; struct { unsigned short int LSB; /* LSB word code */ unsigned short int MSB; /* MSB word code */ }Word; struct { unsigned char byte0; /* bit 7 ~ 0 */ unsigned char byte1; /* bit 15 ~ 8 */ unsigned char byte2; /* bit 23 ~ 16 */ unsigned char byte3; /* bit 31 ~ 24 */ }Byte; }ULONG; void main() { ULONG Data; Data.dwVal = 12345678; printf("Data.dwVal = %ld \n", Data.dwVal); printf("Data.Byte = %ld \n", Data.Byte); printf("Data.Word = %ld \n", Data.Word); printf("Data.Byte.byte3 = %d \n", Data.Byte.byte3); printf("Data.Byte.byte2 = %d \n", Data.Byte.byte2); printf("Data.Byte.byte1 = %d \n", Data.Byte.byte1); printf("Data.Byte.byte0 = %d \n", Data.Byte.byte0); printf("Data.Word.MSB = %d \n", Data.Word.MSB); printf("Data.Word.LSB = %d \n", Data.Word.LSB); printf("Sizeof____Data.dwVal = %d \n", sizeof(Data.dwVal)); printf("Sizeof____Data.Byte = %d \n", sizeof(Data.Byte)); printf("Sizeof____Data.Word = %d \n", sizeof(Data.Word)); printf("Sizeof____Data.Byte.byte3 = %d \n", sizeof(Data.Byte.byte3)); printf("Sizeof____Data.Byte.byte2 = %d \n", sizeof(Data.Byte.byte2)); printf("Sizeof____Data.Byte.byte1 = %d \n", sizeof(Data.Byte.byte1)); printf("Sizeof____Data.Byte.byte0 = %d \n", sizeof(Data.Byte.byte0)); printf("Sizeof____Data.Word.MSB = %d \n", sizeof(Data.Word.MSB)); printf("Sizeof____Data.Word.LSB = %d \n", sizeof(Data.Word.LSB)); }
原文:http://www.cnblogs.com/zhangfan2014/p/4647675.html