Andes Workshop
https://forum.andestech.com/

How to align structure to 8 bytes?
https://forum.andestech.com/viewtopic.php?f=25&t=960
Page 1 of 1

Author:  TangLei [ Wed Aug 10, 2016 12:15 pm ]
Post subject:  How to align structure to 8 bytes?

Programmer may want to align the address of structure to 8 bytes. It lists two ways below:
1.Use an option __attribute__((aligned(8)))before statement of a structure. For example:
typedef __attribute__((aligned(8))) struct{
char a;
char a1;
short b;
short f;
int c;
int d;
char a2;
//__attribute__((aligned(8))) int d;

} typedef_str;


2. Make sure that one of the variable in the structure is double type or 8 byte alignment. For example:
typedef struct{
char a;
char a1;
short b;
short f;
int c;
double d;
char a2;

} typedef_str;

or
typedef struct{
char a;
char a1;
short b;
short f;
int c;
int d;
char a2;
__attribute__((aligned(8))) int d;

} typedef_str;

Page 1 of 1 All times are UTC + 8 hours [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/