Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Ferneu

Is it possible to make a union which behave much like a register?

This topic is 5391 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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)

Share this post


Link to post
Share on other sites
Advertisement

typedef union
{
struct
{
unsigned char xl;
unsigned char xh;
};
unsigned short xx;
} reg_t;


The above assumes a 16-bit register and little-endien.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!