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.

CCS5.5 Compiler Warning (?!) not a fault : use of "=" where "==" may have been intended

Hi

In my code i had the following typo fault.

if (xxx=1) {
   ...
}

Instead of having a fault i had a warning !?

Description    Resource    Path    Location    Type
#189-D use of "=" where "==" may have been intended    main.c    /doublesin_creator    line 35    C/C++ Problem

The result was that, while i was debugging the code x changed its value to 1 !

A strange compiler beahavior.

Tried it on simpler projects e.g. putting the fault if in main or a function) I had an error as it should...

In my case the faulty if was in function that called a function.

I use CCS 5.5.

  • I believe this is correct behavior according to the C language standard(s).  I think you will find most compilers work this way.

    int func()
    {
      return 1;
    }
    
    int main()
    {
      int x = 0;
      if(x = 1)  // legal: first sets x to 1 and then evaluates the value of x.  Compilers may emit a warning.
      {
      }
      if(func() = 1)  // error: can't assign to the return value of func
      {
      }
      if(x = func())  // legal: calls func, assigns the resulting value to x, and evaluates the value of x
      {
      }
      if(1 = x)  // error: can't assign to constant
      {
      }
      if(1 == x)  // legal: alternative form of if(x == 1) that some people prefer because it catches the case when they accidentally wrote if(1 = x)
      {
      }
      return 0;
    }

  • Add the build option --display_error_number, and you'll see that the numeric ID for this diagnostic is 189.

    $ armcl --display_error_number file.c
    "file.c", line 5: warning #189-D: use of "=" where "==" may have been intended

    Now that you know the ID, you can use --diag_error to elevate that diagnostic from a warning to an error ...

    $ armcl --display_error_number --diag_error=189 file.c
    "file.c", line 5: error #189-D: use of "=" where "==" may have been intended
    1 error detected in the compilation of "file.c".
    
    >> Compilation failure

    More on this topic can be learned by watching the video below.

    Thanks and regards,

    -George