Hi,
First of all, I would like to apologize for the time that it has taken us to get back to you on this issue.
We appreciate your patience and want to let you know that we are doing efforts to improve our response time.
See below some info regarding the structure Alignment.
Hope this will help you.
Problem: Explanation/Clarification on structure alignment.
Description:
Question regarding the structure alignment.
Se below an example showing the problem.
See car2,car3,car4,car5,car6 and car7.
The tool reserve an int instead of a char.
Is it not possible to align better the structure ?
typedef struct
{
union
{
struct
{
unsigned int Bit0 :1;
unsigned int Bit1 :1;
unsigned int Bit2 :1;
unsigned int Bit3 :1;
unsigned int Bit5 :1;
unsigned int Bit6 :1;
unsigned int bit7 :1;
unsigned int Bit8 :1;
unsigned int Bit9 :1;
unsigned int Bit10 :1;
unsigned int Bit11 :1;
unsigned int Bit12 :1;
unsigned int Bit13 :1;
unsigned int Bit14 :1;
unsigned int Bit15 :1;
} B;
int W16;
} car01;
union
{
unsigned char var1;
unsigned char var2;
unsigned char var3;
} car2;
union
{
unsigned char var1;
unsigned char var2;
unsigned char var3;
} car3;
union
{
unsigned char var1;
unsigned char var2;
unsigned char var3;
} car4;
union
{
unsigned char var1;
unsigned char var2;
unsigned char var3;
} car5;
union
{
unsigned char var1;
unsigned char var2;
unsigned char var3;
} car6;
union
{
unsigned char var1;
unsigned char var2;
unsigned char var3;
} car7;
}my_struct;
typedef union
{
my_struct data;
unsigned char car[8];
long int W32[2];
}my_2ndStruct;
Resolution:
The specifications for 56800e are such that we cannot modify this behavior in build tools.
If you look into Targeting_56800E.pdf at data alignment requirements, one can see "
• Structures — word boundaries (not byte boundaries).
NOTE A structure containing only bytes still is word aligned.
This holds also for unions.
This is why you can see one byte padding, besides the char data.
The structure mytest has 2 int and 2 char and take 3 int only.
According to the manual is should take 4 int.
struct
{
int test1;
int test2;
char test3;
char test4;
}mytest;
Please note that the specifications are for data alignment and not data size.
So, char can be aligned on byte boundary.
That is why in second example you see test4 aligned on byte boundary.
Still, if test4 is included in another structure or union, it has to
stay on word boundary because of the restrictions for structures.
That is why one byte padding will be introduced between test3 and test4.
So, yes the entire structure mytest will take 4 ints here:
struct
{
int test1;
int test2;
char test3;
union
{
char test4;
};
}mytest;
Regards
Pascal Irrle