In one of the header files of C I came across of the syntax __align(4)
before an ·unsigned char·, I would like to know its purpose and what will happen if I remove it? Where can I use it?
There is nothing in the C language called __align(). It appears to be a non-standard language extension.
Most likely it aligns a variable at a certain memory boundary. For example __align(4) uint8_t x;
will likely guarantee that x
is allocated at an even address divisible by 4.
Since C11, the C language has a similar keyword _Alignas
which works in the same manner.
If you would remove it from the file, the variable will get allocated where the compiler seems fit, depending on the alignment requirements of the specific system. Depending on optimizing settings (optimize for speed or optimize for program size), it may or may not be allocated at a different address.