Hi All,
Please excuse my profound ignorance and inevitable lack of tact. I have a simple question about defining a structure/union. Is there a more elegant, possibly simpler way to achieve the following?
The goal is to end up with a union allowing the same data to be referenced in different contexts - as in discrete elements or as a data buffer.Code:typedef unsigned char BYTE; // 8-bit unsigned typedef unsigned short int WORD; // 16-bit unsigned typedef struct{ BYTE month; BYTE day; BYTE hour; BYTE minute; BYTE second; }sTimeStamp; typedef struct{ WORD resolution :4; WORD temperature :12; }sReading; typedef struct{ sTimeStamp time; sReading sensor1; sReading sensor2; sReading sensor3; sReading sensor4; }sSample; typedef union{ sSample elements; BYTE bytes[sizeof(sSample)]; }uSample;
This method strikes me as a bit verbose, but fairly comprehensible.
Thanks for any input.