标签:
1. 记账信息结构联合
typedef struct {
unsigned int areaNum;
unsigned int transNum;
unsigned int station;
} phoneNumber;
struct {
phoneNumber fromPhone;
phoneNumber toPhone;
phoneNumber payPhone;
} dialHistory;
2. 指令解码:
#include <stdio.h>
typedef struct {
unsigned int dsg_reg : 3;
unsigned int dst_mode: 2;
unsigned int opcode : 11;
} sgl;
typedef struct {
unsigned int dst_reg : 3;
unsigned int dst_mode: 3;
unsigned int src_reg : 3;
unsigned int src_mode: 3;
unsigned int opcode : 4;
} dbl;
typedef struct {
unsigned int offset : 8;
unsigned int opcode : 8;
} bran;
typedef struct {
unsigned int dst_reg : 3;
unsigned int dst_mode : 3;
unsigned int src_reg : 3;
unsigned int opcode : 7;
} reg;
typedef struct {
unsigned int opcode : 16;
} mic;
typedef union {
unsigned short addr;
mic misc;
bran branch;
sgl sgl_op;
reg reg_src;
dbl dbl_op;
} machine_inst ;
int main()
{
machine_inst x = {16};
printf("%0x\n", x.sgl_op.dst_mode);
return 0;
}
typedef 定义联合类型,就可以使用各种联合内的字段结构,访问了
标签:
原文地址:http://www.cnblogs.com/yangxunwu1992/p/5835744.html