Search code examples
cgccarmalignment

How many byte alignment for arm?


I am programming C on a arm cortex cpu with gcc-arm-none-eabi. I know it is 4-byte alignment by test and google.

But is there any macro or variable which defines how many bytes alignment it is? I need know in case someday this program may be port for another cpu.


Solution

  • A trick to find the alignment of a particular data type is to pack it in a struct with a char:

    #define LONG_ALIGNMENT (sizeof (struct {char a, long b}) - sizeof (long))
    #define INT_ALIGNMENT  (sizeof (struct {char a, int b}) - sizeof (int))