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.

TMS320F28388D: How to avoid structure padding in C2000

Part Number: TMS320F28388D

Hi Team,

I am using TMS320F28388 controller with CCS 11.

While writing the program I have to use a structure like below.

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
struct HostReply
{
uint16_t Length;
uint32_t BoardStatus;
uint32_t SignalStatus;
union
{
uint16_t Data; // for Read, CRC16 for Write
uint16_t CRC16; // so that sizeof(HostReply) = sizeof(Length) + sizeof(BoardStatus) + sizeof(CRC16)
} Data_CRC;
};
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

But when I copy the structure data to a buffer, the Length variable is added with extra 2bytes of data. I understood this is structure padding and tried to avoid that using #pragma packet(1) header.

But got a warning like #163-D unrecognized #pragma.

Can you help me to fix this issue and pack the structure properly.

Thanks in advance

Dipin

  • Dipin,

    Have you tried changing the order. 

    struct HostReply
    {
    uint16_t Length;

    union
    {
    uint16_t Data; // for Read, CRC16 for Write
    uint16_t CRC16; // so that sizeof(HostReply) = sizeof(Length) + sizeof(BoardStatus) + sizeof(CRC16)
    } Data_CRC;

    uint32_t BoardStatus;
    uint32_t SignalStatus;


    };