Hi,
I have read that __align is used to set the boundary of variable, what is its benefit.
suppose __align(2) unsigned short u;
even unsigned short variable can have its value from 0 to 65535. then where is difference lies.
second thing, can we say that __align is a qualifier in c/c++.
Thanks.
These days, many compilers take this into account, especially for processors that are very picky about misalignment. It is best to search the compiler manual since it can vary between vendors.
the aligned thing is called a compiler directive. This is an instruction executed by you compiler to set the alignment of the variable defined later. This is needed because machines, like ARM, are aligned machines. If addresses are not aligned with data sizes, this will generate a hardware fault. In general, aligned machines provide faster chunks of data access and address generation.
a correction:
----------------------------------------
instead of
addr0 ---
addr1 byte0
addr2 byte1 ---now the processor reads two times.
addr2 ---
first addr0 and 1---get the byte0
second addr1 and 2---get byte1
--------------------------------------------
read as:
addr0 ---
addr1 byte0
addr2 byte1 ---now the processor reads two times.
addr3 ---
first addr0 and 1---get the byte0
second addr2 and 3---get byte1
a compiler meant for that processor takes care of alignment.
no need to specify separately for basic codes.
eg:
gcc -basic c ------takes care of.
for sse codes , special alignment commands are included in header files.