Purpose
I am writing a network program in C (specifically gnu89) and I would like to simplify things by reinterpreting a certain
We use this technique frequently to convert messages between a byte array and a structure, and have never encountered problems with it. You may have to perform endianness conversion yourself, but field order isn't a problem. If you have any concerns about data type sizes, you can always specify field size like so:
struct foo
{
short someField : 16 __attribute__ ((packed));
};
This guarantees that someField will be stored as 16 bits and will not be rearranged or altered to fit byte boundaries.