Good day!
I am trying to run C code written for GNUC and msvc on my C8051F320 MCU (Cx51 compiler). While compiling errors are generated, that direct me to the following lines:
#ifdef __GNUC__ #define PACKSTRUCT( decl ) decl __attribute__((__packed__)) #define ALIGNED __attribute__((aligned(0x4))) #else //msvc #define PACKSTRUCT( decl ) __pragma( pack(push, 1) ) decl __pragma( pack(pop) ) #define ALIGNED #endif
That is why I need to rewrite that defines macros to make Cx51 compiler understand me. I don't know how to do this at the moment.
Thank you beforehand!
Best regards, SANEL
well, in an 8-bitter, you do not need packed/aligned. just get rid of it
Erik
As always, the prio 1 step is always to make sure to understand the structures of a program. First when they are understood can the code be modified to work (or at least work well) on another architecture.
Packing of data really relates to processors that have a very wide memory interface and that either lose lots of performance - or even totally fails - when accessing large data objects that are placed at odd addresses making the variable being split over two 16-bit or 32-bit or 64-bit (or even wider) memory cells.
When the processor have 8-bit memory cells and are only able to read and write in 8-bit quantities, there isn't really any need to insert any padding to properly align larger data types. And with no padding, there isn't a need to request the compiler to pack the data, i.e. to stop adding any padding.
Erik,
Thanks a lot. You save my time.
SANEL
Per,
Thank you for your answer. That's useful.