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.

[参考译文] 编译器/TMS320F28377S:#69-D 整数转换导致符号改变

Guru**** 2555630 points


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

https://e2e.ti.com/support/tools/code-composer-studio-group/ccs/f/code-composer-studio-forum/690345/compiler-tms320f28377s-69-d-integer-conversion-resulted-in-a-change-of-sign

器件型号:TMS320F28377S

工具/软件:TI C/C++编译器

您好!

我在用于 Mistral EVM3530板的 DVSDK 4.00.00.22 (xdctools 3.16.03.36)下开发 DSP 应用(C64x+)、我收到了有关 无符号整型(32位)的以下警告、但这不应出现、因为它是无符号整型

//与 CRC 相关
#define polynomial 0x1021
#define INinitial_remainder 0xFFFF
#define final_XOR_value 0x0000
#define width (8 * sizeof (width))(定义宽度(8 * sizeof (width))))
#define TOPBIT (1 <<(宽度- 1))
typedef unsigned long width;
typedef unsigned char 字节;
宽度 crcTable[256];

空 initcrc(void)

无符号短整型余数;

无符号短除数;//将16位 CRC 除以4位

INT 位;

对于(被除数= 0;被除数< 256;被除数++)

余数=除数<<(宽度- 8);

对于(位= 0;位< 8;位++)

if (余数和 TOPBIT)  <--- 误差点

余数=(余数<< 1)^多项式;

其他

余数=余数<< 1;

crcTable[除数]=余数;

unsigned short calcurateCRC (unsigned char *消息、unsigned int nbytes)

unsigned int offset;
unsigned char 字节;
unsigned short remainder = inited_remainder;

对于(偏移= 0;偏移< nbytes;偏移++)

字节=(余数>>(宽度- 8))^消息[偏移量];
余数= crcTable[字节]^(余数<< 8);

返回(余数^ final_XOR_value);

unsigned short MakeCRC16 (unsigned char * sData、int iDataAgent)

unsigned short crc16;

initcrc();
crc16 = calcurateCRC (sData、iDataAgent);

返回(crc16);

我在 TI 论坛上搜索过它、但未找到答案。

为了避免这种错误警告、我应该怎么做?  如果存在此选项、是否应删除所有符号转换检查?

 

谢谢、

 

Lee

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

    TOPBIT 中的值从有符号变为无符号。  您可以通过使 TOPBIT 从一开始就无符号来避免诊断。  将 u 后缀添加到1,如下所示...

    #define TOPBIT (1U <<(宽度- 1)) 

    我注意到另一个可能的错误。  C28x 上 char 的大小为16位、而不是8位。 这个#define 中的8似乎...

    [引用 user="MINSIK LEE"]#define width (8 * sizeof (width)))

    (笑声) 假设 char 为8位。  进行两项更改可能是有意义的...

    #include //对于 char_bit
    //跳过一些行
    #define width (char_bit * sizeof (width)) 

    在 C28x 上、char_bit 为16。  对于几乎所有其他 CPU、它是8。

    当我在您的示例中进行这些更改时、会发出一些其他错误消息。  但我怀疑这些线路无论如何都需要审查。

    谢谢、此致、

    乔治

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

    我对此表示赞赏。

    Lee