Compilers are free to do what they like, as the memory locations coincide with members of structures and associations and other complex data structures.
I saw cryptic runtime errors using structures that were caused by boundary alignment problems because one part of the source saw the structure in one direction and the other saw it in a different way.
C basically uses structure as a template for overlaying a region of memory, and if different files see the structure differently, one piece of code calculates the address offset for a structure element that is different from another.
Some compilers will provide a pragma that allows you to specify the action of the package so that you can specify the alignment boundary of the structure members.
To maintain hardware compatibility, the best way is to use unsigned character arrays, because in this way you can index an element without an unsigned character, and then select one of eight bits with bitwise operators. You can then wrap an array of unsigned characters in various access functions, classes, macros, etc., to manipulate the actual data that you want to read and write. Using unsigned character arrays is also more portable.
The bit fields are apparently more suitable for the application to maintain indicators and flags in memory saving mode, but are not so useful for communicating with objects (hardware or software) outside the application. And depending on the compiler and the hardware on which the application is running, the use of bit fields can lead to a small penalty for execution, since access to bits is applied to them, they are packed and unpacked.
source share