ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
In computer memory, each byte is stored and accessed in a linearly numbered range of addresses. When multiple bytes are used to make up a larger data type, such as integers, long integers, floating point types, and address types, the alignment of the multiple bytes within the address space may fall on boundaries that are or are not aligned with the storage size for that data type. For example, a 4-byte data type may start at an address that is an even multiple of 4, or not. Some/most/many CPU types are optimized to fetch a multi-byte word from a memory whose base address is a multiple of the size of that data. When a compiler/linker arranges the data segment components, it may or not arrange for the various data objects to be optimally aligned on addresses favorable to the particular CPU. It becomes a trade-off between speed and memory usage.
Its not a complex subject. My previous reply pretty much covers it. If you want nitty-gritty detail, you should look in the data books for the various CPUs that you are interested in &/or the manuals for whatever compiler(s) you want to use. Exactly what sort of information do you need?
actaully i have an arm-based processor board and the compiler i use is armcc and when i run my executable file on the hardware i got an error and i think this is because the unaligned data?
so i just want to know general information about data alignment then see what that arm processor specs and that armcc compiler options.
Okay, then you need to consult the reference manual for your Arm processor, and/or the C compiler documentation. If the board and compiler support a debugger such as gdb, then that may be a useful tool, as well.