Keil Logo


aligned(n) is a variable and function attribute that specifies a minimum alignment for a variable, structure field, or function. n specifies the alignment in bytes.

  • The aligned attribute has precedence over the directive ORDER.
  • The keyword _at_ overrules the alignment.


** Aligns on 16-byte boundary
int x __attribute__((aligned (16)));

** Aligns on 8-byte boundary
struct S { short f[3]; } __attribute__ ((aligned (8)));

** Declares a type which aligns variables on 4-byte boundaries
typedef int more_aligned_int __attribute__ ((aligned (4)));
more_aligned_int int_aligned;

** Declares a struct where a field is aligned
** Element y will begin on a 4 byte boundary creating a gap between x and y
struct Al {
  char  x;
  char  y __attribute__((aligned(4)));
Struct Al value;                       /* value will be aligned on a 4 byte boundary */

** Defines a function which begins on a 32 byte boundary
int function(int a, int b) __attribute__((aligned(32)))
  return a*b;

See also:

  Arm logo
Important information

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies.

Change Settings

Privacy Policy Update

Arm’s Privacy Policy has been updated. By continuing to use our site, you consent to Arm’s Privacy Policy. Please review our Privacy Policy to learn more about our collection, use and transfers
of your data.