Pack struct on 56F8367

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Pack struct on 56F8367

1,614 Views
TheSealion
Contributor I
Hello,
 
I tried to use a union of struct and char array to handle data in RAM and save it to an I2C EEPROM.
 
On other controllers this was no problem because the compilers put one variable of the struct after the other.  The CodeWarrior leaves some addresses blank. Is it possible to configure it the way he didn't leave spaces?
 
Mike


Message Edited by TheSealion on 2007-05-11 12:57 PM
Labels (1)
Tags (1)
0 Kudos
1 Reply

173 Views
trytohelp
NXP Employee
NXP Employee
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
0 Kudos