Andes Workshop

It is currently Fri Oct 11, 2024 8:36 am

All times are UTC + 8 hours [ DST ]




Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: How to align structure to 8 bytes?
PostPosted: Wed Aug 10, 2016 12:15 pm 
Offline

Joined: Thu Jan 07, 2016 12:29 pm
Posts: 5
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;


Top
 Profile Send private message E-mail  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC + 8 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group