Say I have a C structure like:
typedef struct {
UINT8 nRow;
UINT8 nCol;
UINT16 nData; } tempStruct;
Is there a way to put all of those 3 members of the struct into a single 32-bit word, yet still be able to access them individually?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
What about just referring to it as a UINT32? It’s not like C is type-safe.
You can then get the value of the struct as a 32-bit word by dereferencing the pointer. The specifics of your system may matter, though…if I run this on my machine, the value of
wordis 0x00040201—that is, the fields are in reverse order. I don’t think that’s necessarily going to be the case if you’re trying to serialize this to another system, so it’s not portable.If you want to actually store it as a 32-bit integer and then refer to the fields individually, why not
and then somewhere else…
Macros will facilitate portable endianness.