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.

C2000 Compiler (6.1.4) doesn't generate loss of data warning

Guru 20075 points

Hello,

The compiler doesn't generate a warning for the following code. I would expect the compiler to generate a loss of data warning for the line b=a.

I am using C2000 compiler version 6.1.4.

Stephen

int main(void)

{    

   unsigned long int a = 1;

   char b =2;

   b = a;

   return 0;

}

  • stevenh said:
    I would expect the compiler to generate a loss of data warning for the line b=a.

    Agree that the C2000 compiler version 6.1.4 doesn't by default generate a warning for that line, even when the --verbose_diagnostics and --issue_remarks options are used.

    However if MISRA 10:Arithmetic type conversion rules are enabled by the --check_misra="10" option then do get a warning:

    "../main.c", line 28: warning #1393-D: (MISRA-C:2004 10.1/R) The value of an
              expression of integer type shall not be implicitly converted to a
              different underlying type if it is not a conversion to a wider
              integer type of the same signedness
         b = a;
  • Thanks for the reply.

    I guess I'll have to start using MISRA, however, it seems that such an important warning shouldn't be missed by the compiler.

    Thanks,

    Stephen

  • The compiler does not emit such a remark by default because there is a large body of perfectly functional code that would get a huge number of warnings.  The example given in the original post, for example, works as intended despite the implicit conversion.

  • MISRA 10.1 generates lots and lots... and lots of warning. :(

    Also, it doesn't give the complete warning string.  Is there anyway to correct that issue?

    Stephen

  • stevenh said:
    Also, it doesn't give the complete warning string.  Is there anyway to correct that issue?

    With CCS 5.4 I found that that the CDT Build Console gives the complete MISRA warning string (which is split over more than one line) whereas the description in the Problems tab only gives the first line of the warning. Are you seeing the partial warning string in the CCS Problems tab?

    This is a known issue with CCS - see error description truncated in problems view

  • Hello Chester,

    You're correct. Its gives the complete string in the console window.

    Thanks,
    Stephen