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.

TMS320F28075: Compiler Options - Implicit Conversion Detection

Part Number: TMS320F28075

Tool/software:

Hi,

We are using CCS 9.0.1.00004 , Compiler version TI v18.1.2.LTS,

We would like to activate the following option: "-Wsign-compare" or equivalent if this does not exists in our case.

The underlining reason for it was that we saw the sometimes a comparison between negative signed integer and a positive unsinged would result in negative being larger the the positive (we assume implicit conversion)

the following is an example for this case:

    int one = -5;
    unsigned int two = 5;

    if(one > two)
    {
        one++;
        one++;
        one++;
    }

Thanks,

  • We would like to activate the following option: "-Wsign-compare" or equivalent

    Build with --issue_remarks and you will see a diagnostic similar to ...

    "file.c", line 8: remark: comparison between signed and unsigned operands

    we saw the sometimes a comparison between negative signed integer and a positive unsinged would result in negative being larger

    The C language specification is the reason.  When an operation combines unsigned and signed expressions, the signed expression is implicitly converted to unsigned.  A signed expression is converted to unsigned simply by re-interpreting the bits.  No actual operation occurs.  In this specific case, -5 becomes 0xfffb.  To underscore this point, I tried this experiment with Compiler Explorer.  Note I set the option -O, which means everything is optimized away, except for a call to either unexpected or expected.  With every compiler I tried, I always see a call to unexpected.

    Thanks and regards,

    -George

  • Thank You,

    Your answer did the trick for us and the online compiler you linked may prove helpful as well.