Hi all! I am experiencing the following problem:
sizeof(EDA.stPARAM) returns 0x80 with CA.exe V2.41 which in my opinion is the correct result, but with CA.exe V2.50a it returns 0x82. Can somebody explain this behaviour to me? Code sample is included below:
file eda_st.inc:
struct {
byte ubFree_0000h[16] ;/* 000h-00Fh: */
byte ubFree_0010h[16] ;/* 010h-01Fh: */
byte ubFree_0020h[16] ;/* 020h-02Fh: */
byte ubFree_0030h[16] ;/* 030h-03Fh: */
byte ubFree_0040h[16] ;/* 040h-04Fh: */
byte ubFree_0050h[16] ;/* 050h-05Fh: */
byte ubFree_0060h[16] ;/* 060h-06Fh: */
byte ubFree_0070h[16] ;/* 070h-07Fh: */
}stPARAM;
byte VER_HWVers ;/* 000h: */
byte ubFree_0000h[127] ;/* 001h-07fh: */
}stABGLEICH;
---------------------- file eda_usr.h:
typedef struct {
#include "eda_st.inc" // struct mit Parametern
} EDA_sttyDAT;
extern EDA_sttyDAT EDA;
---------------------- file eda_usr.c:
#define TAR_RAMCOPY 0x40001000
EDA_sttyDAT EDA __at(TAR_RAMCOPY);// RAM-Kopie
Maybe the compiler want to add an extra byte of empty data at end of struct, to make sure that it is allowed to do a 16-bit access to the last byte without overflowing into unknown data space.
But since 1 bytes of overflow protection makes the struct incorrectly aligned, the compiler then has to add more padding.
Never depend on a specific size of a data structure.
By the way, why are you plaing with include files when defining your struct? It doesn't help readability.
I just noticed that I used an old MAP file. The size of the EDA struct DOES match the sum of the sizeof values. But I still don't understand why there is a different behaviour in compiler version 2.51a in comparison to version 2.41. Thanks to all for your advice.