Use typedef to declare an identifier as a name for a type before it is referenced in the code. By being so explicit, the compiler does not have to make any assumptions regarding type sizes. For application specific objects that must be a precise size, create a complete set of unique typedefs. These application-specific data types and structures can be modified, minimally affecting the source code that uses these data types. Data Structure Padding Never assume offset sizes in data structures.
Different compilers pack and size structures differently.
The best way to handle this is to use a macro wherever possible to ensure that the correct byte alignment will be achieved. To eliminate alignment and packing issues, avoid casting a memory location for a specific structure member or component, or for a location within the structure member itself. Also, use the sizeof operator when referencing the size of a structure. Do not use hard-coded constant valuesfor sizes. A portable set of routines or macros may be used to extract data by byte-swapping as necessary.