共用体使用常用规范

来源:互联网 发布:php implements 编辑:程序博客网 时间:2024/06/14 07:41

  在大型的软件系统中,共用体也是经常使用的,一般的话,共用体为了保证字节数对齐,所以一般保持总的所占的内存字节数应该是相等的。

union DECODE

{
uint32_t    dword[4];
uint16_t   word[8];
uint8_t   byte[16];

};

uint32_t占用4个字节,4*4=16 uint16_t占用2个字节 2*8=16 uint8_t占用1个字节,1*16=16;


0 0
原创粉丝点击