structure paddinf : codewarrior compiler

cancel
Showing results for 
Search instead for 
Did you mean: 

structure paddinf : codewarrior compiler

170 Views
FIDDO
Contributor III

Hi,

I have a doubt in strucure padding relavant to code warrior IDE.  I'm working on a 16 bit microcontroller mc9s12xhy.

typedef struct{

unsigned int x;

unsigned char y;

}Error_mode;

Error_mode Error_mode_Data;

While compiler compiles the code, it shall allocate 4 bytes for Error_mode_Data ( with padding  refernce: .map file ). It doesnt seem to happen. It s allocating 3 bytes only. Hw to switch on/off padding in a code warrior compiler? this is critical coz of im using for EEPROM write/read!

Labels (1)
0 Kudos
1 Reply

80 Views
Rick_Li
NXP Employee
NXP Employee

Hi,

unsigned char is 1 byte in CodeWarrior for HCS12. so, this struct will take 3 bytes after compiled.

maybe the better way to do that is to define the element y as unsigned int.

If you just want the generated struct is aligned with 2bytes, then, you can also add "ALIGN 2" in the prm file follows the memory address like below:

  EEPROM_00 = READ_ONLY   DATA_FAR IBCC_FAR  0x000800 TO 0x000BFF ALIGN 2;

then, all data in EEPROM_00 will be aligned with 2 bytes.

I hope it helps!

0 Kudos