union的使用

union中的各个字段共享同一块内存区域

typedef union

{

undigned short int value;

unfigned char bytes[2];

}to;

to typeorder;

typeorder.value = 0xabcd;

那么:

bytes[0] = 0xcd;

bytes[1] = 0xab; //如果是Low endian的话

 

posted @ 2019-08-14 16:40  boboyou  阅读(394)  评论(0编辑  收藏  举报