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.

[参考译文] 对位字段的赋值不#39;t 发出截断警告

Guru**** 2568565 points


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

https://e2e.ti.com/support/tools/code-composer-studio-group/ccs/f/code-composer-studio-forum/1181797/assignment-to-bit-field-doesn-t-warn-of-truncation

您好!

我很想知道编译器为什么不警告我、如果分配的值对于位字段来说太大、就会发生截断。 我有以下位字段:

struct packed_tag {
     uint32_t lower_word:16;
     uint32_t higher_word:16;
}pack0;

我只在以下代码的第一行获得"#70-D:整数转换导致截断"、而不是第二行。 为什么会这样?

    uint16_t my_uint = 0x10000U;
    pack0.lower_word = 0x10000U;

谢谢你。

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

    其他几个编译器在...时发出诊断

    [引用 userid="479799" URL"~/support/tools/code-composer-studio-group/ccs/f/code-composer-studio-forum/1181797/assignment-to-bit-field-doesn-t-warn-of-truncation "]位字段的分配值过大[/quot]

    因此、我在  编译器中提交了 EXT_EP-11008以请求进行此更改。  欢迎您访问该链接。  请理解、这并不能保证进行任何更改。

    谢谢、此致、

    乔治

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

    非常感谢 George。