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:如何在 C2000中避免结构填充

Guru**** 2539500 points


请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

https://e2e.ti.com/support/microcontrollers/c2000-microcontrollers-group/c2000/f/c2000-microcontrollers-forum/1169967/tms320f28388d-how-to-avoid-structure-padding-in-c2000

器件型号:TMS320F28388D

大家好、

我将 TMS320F28388控制器与 CCS 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;
};

但是、当我将结构数据复制到缓冲区时、长度变量会添加额外的2字节数据。 我知道这是结构填充、并尝试避免使用 #pragma packet (1)标头。

但得到了像 #163-D 无法识别的#pragma 这样的警告。

您能帮我解决这个问题并正确封装结构吗?

提前感谢

双引脚

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    双引脚、

     您是否尝试更改订单。  

    结构 HostReply

    uint16_t 长度;

    UNION

    uint16_t 数据;//用于读取、CRC16用于写入
    uint16_t CRC16;//因此 sizeof (HostReply)= sizeof (Length)+ sizeof (BoardStatus)+ sizeof (CRC16)
    } Data_CRC;

    uint32_t 板状态;
    uint32_t SignalStatus;


    };