This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Data alignment

Hi,

My system includes two different processors, which shares some memory. Each processor runs code generated by two absolutely different development environments.  In order to allow data sharing between two processors I would like to force 1 byte alignment of common data structures (on both sides).

 

typedef  struct

{

    unsigned char    Ch;

    unsigned int     Int;

    unsigned short   Sh;

}  MyStructType;

 

MyStructType S1;

 

 

As result of compiler padding sizeof(S1)  is 12 bytes.

 

I tried two pragma directives:

    1. #pragma STRUCT_ALIGN(MyStructType, 1)

    2. #pragma DATA_ALIGN(S1, 1)

But sizeof(S1) remains 12 (I expect to get 7)

Platform description:

Development environment:   CCS 3.3

Target DSP:                                     DM6435

Thanks in advance,

                                 Alex. 

 

  • For what you are trying to do it sounds like you are really looking for a '#pragma pack' directive, which does not exist within the TI code generation tools, which means there is not a way to override the default byte padding that goes into such structures that I am aware of.

    Alex said:

    I tried two pragma directives:

        1. #pragma STRUCT_ALIGN(MyStructType, 1)

        2. #pragma DATA_ALIGN(S1, 1)

    But sizeof(S1) remains 12 (I expect to get 7)

    These pragmas are for aligning the entire object to a particular boundary in memory, they do not impact the content of the object, just what address it starts at. Note that setting an alignment of 1 means it is going to align to a single byte boundary which is the minimal addressable unit size for C6x devices already, so it effectively does nothing.