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.

TMS320F280039C: struct data alignment

Part Number: TMS320F280039C

Tool/software:

Hi Champ,

I am asking for my customer.

The compiler will automatically putting 0 for data alignment when the structure variables are declared in the following way, it makes the structure multiples of 4Byte all the time.

Is there a way so that the variables are placed consecutively, and do not automatically putting 0 to make it for 4Byte

typedef struct _test

{

unsigned char a ; // 2 bytes

unsigned int b; // 4 bytes 

} test ;

Thanks and regards,

Johnny

  • On C28x, the type char is 16-bits wide.  Therefore the total size of ...

    typedef struct _test

    {

    unsigned char a ; // 2 bytes

    unsigned int b; // 4 bytes 

    } test ;

    ... is 32-bits.  

    You might be interested in the article Byte Accesses with the C28x CPU.

    Thanks and regards,

    -George

  • Hi George,

    Thanks for the reply.

    From my understanding, C2000 compiler does not support attribute packed support.

    User may have to manually declare variables in sequence for data alignment for size saving.

    In latest finding, in project A, in the case where the len variable is consecutive, not added with 0s to the next struct, std structure. 

    In project B, there is a complement of 0s after the len variable, then following declare the address for the DSP_CFG structure.

    Where the std is 8byte struct, and the DSP_CFG is 16byte struct. 

    (1). Asking on why in project A, the len variable is not be filled with 0s following to the next struct ?

    (2). Is there a compiler data alignment rule available to user ?

    Thanks and regards,

    Johnny

  • Is there a compiler data alignment rule available to user ?

    Yes.  Please search the C28x compiler manual for the sub-chapter titled Field/Structure Alignment.  One point it does not make clear: The alignment of a struct is the maximum of the alignment of any of its members.

    Asking on why in project A, the len variable is not be filled with 0s following to the next struct ?

    It must be the case that the structure type struct_GUI_STD_Co... contains no members that require 2-word alignment, and so it can start on an odd word address.  By contrast, the structure type struct_DSP_Config must contain at least one member that requires 2-word alignment, and so it must start on an even word address.

    Thanks and regards,

    -George