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.

Compiler/TMS320F28377S: #69-D integer conversion resulted in a change of sign

Part Number: TMS320F28377S

Tool/software: TI C/C++ Compiler

Hi,

I develop DSP applications (C64x+) under DVSDK 4.00.00.22 (xdctools  3.16.03.36) for the Mistral EVM3530 board and I got the following  warning about an unsigned int (32 bits) but this should not appears because it is unsigned

//Relate to CRC
#define POLYNOMIAL 0x1021
#define INITIAL_Remainder 0xFFFF
#define FINAL_XOR_VALUE 0x0000
#define WIDTH (8 * sizeof(width))
#define TOPBIT (1 << (WIDTH - 1))
typedef unsigned long width;
typedef unsigned char byte;
width crcTable[256];

void initCRC(void)
{

unsigned short Remainder;

unsigned short dividend; // Divide 16bit CRC by 4bit

int bit;

for (dividend = 0; dividend < 256; dividend++)

{

Remainder = dividend << (WIDTH - 8);

for (bit = 0; bit < 8; bit++)

{

if(Remainder & TOPBIT)   <------Error Point

Remainder = (Remainder << 1) ^ POLYNOMIAL;

else

Remainder = Remainder << 1;

}

crcTable[dividend] = Remainder;

}

}

unsigned short calcurateCRC(unsigned char *message, unsigned int nBytes)
{
unsigned int offset;
unsigned char byte;
unsigned short Remainder = INITIAL_Remainder;

for (offset = 0; offset < nBytes; offset++)
{
byte = (Remainder >> (WIDTH - 8)) ^ message[offset];
Remainder = crcTable[byte] ^ (Remainder << 8);
}
return (Remainder ^ FINAL_XOR_VALUE);
}

unsigned short MakeCRC16(unsigned char *sData, int iDataLen)
{
unsigned short crc16;

initCRC();
crc16 = calcurateCRC(sData, iDataLen);

return (crc16);
}

I did a search on Ti forum about it but not find answer.

What should I do to avoid this false warning?  Should remove all sign conversion checking if this option exist?

 

Thank you,

 

Lee

  • The value in TOPBIT changes from a signed to unsigned.  You can avoid the diagnostic by making TOPBIT unsigned from the beginning.  Add the u suffix to 1 like this ...

    #define TOPBIT (1u << (WIDTH - 1))

    While I have your attention, I notice one other possible error.  The size of char on C28x is 16-bits, not 8-bits. It appears that the 8 in this #define ...

    MINSIK LEE said:
    #define WIDTH (8 * sizeof(width))

    ... is a presumption that char is 8-bits.  It may make sense to make two changes ...

    #include <limits.h>  // for CHAR_BIT
    // skip some lines
    #define WIDTH (CHAR_BIT * sizeof(width))

    On C28x, CHAR_BIT is 16.  For nearly every other CPU, it is 8.

    When I make these changes in your example, a few other error messages are emitted.  But I suspect those lines need to be reviewed anyway.

    Thanks and regards,

    -George

  • Thanks for your comments.

    i appreciate it.

    LEE