__attribute__((aligned (x)))

Sets the memory boundary for storing data objects.

Syntax
  declaration __attribute__ ((aligned(x)));
  
  

x - a decimal power of two ranging from 1 to 4096.

Remarks

The attribute overrides the natural alignment of the object when used on a struct member.

Structure member alignment examples:

The following structure member definition aligns all definitions of struct S3 on an 8-byte boundary, where a is at offset 0 and b is at offset 8.

  struct S3 {
  
  
  char a;
  
  
  int b __attribute__ ((aligned (8)));
  
  
  };
  
  
  struct S3 s3;
  
  

The following struct member definition aligns all definitions of struct S4 on a 4-byte boundary, where a is at offset 0 and b is at offset 4.

  struct S4 {
  
  
  char a;
  
  
  int b __attribute__ ((aligned (4)));
  
  
  };
  
  
  struct S4 s4;
  
  
Note: Structs do not inherit the alignments of the struct members.