Is it possible to make a union which behave much like a register?
Is it possible to make a union which behave much like a register? I mean, you could create, lets say XX, and then, after assigning a value to XX, we could get the lower and higher part of the value, with XL and XH. I mean:
XX = 0x1234;
XL = 0x34;
XH = 0x12;
From what I understand about unions, I would go to somethin like this:
typedef union {
unsigned int XX;
unsigned char XL;
} reg_t;
reg_t lol;
lol.XX = 0x1234;
This way, lol.XL would get the 0x34, but how can I create a variable inside the union that could get the 0x12? (case that is possible)
typedef union{ struct { unsigned char xl; unsigned char xh; }; unsigned short xx;} reg_t;
The above assumes a 16-bit register and little-endien.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement