Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

The "=" and loop termination warning

2008-06-27
2013-03-12
  • Hi,
    I have done quite a few projects on 8051(keil) and avr(gcc-avr) but this is my first venture into PIC as well as SDCC. Here are two of the bugs (I am not sure if it's considered more as a missing feature than bug) I came across in SDCC:

    1. The "=" vs "==":
       Considering the following code:
                                        /*some c code
                                        ...........*/
                                        if(i=3)               //----------This would actually cause a warning in keil as well as gcc-avr-----------
                                        {
                                              /*do something
                                              .............*/
                                        }

    1. The loop terminator:
       Considering the following code:
                                        /*some c code
                                        ...........*/
                                        if(i=3);               //----------This would actually cause a warning in keil as well as gcc-avr----------

    Though I can't remember what the warning text is, I am sure that both keil and gcc-avr generates a warning for the above two instances. If the SDCC moderators would implement this feature, it will be helpful for programmers like me who make a lot of silly mistakes like these. ;)

    PS: I was not sure if this was considered as a BUG or a MISSING FEATURE (which most were aware and didn't mind it since they don't commit silly mistakes like me ;p), so I didn't report it as a bug. If any of you guys out there feel that this is to be implemented, let's report it as a bug.

    Cheers ;p

     
    • it's legal C, so it doesn't have to generate a warning. Lint, QAC, Polyspace and other code analysis tools will find these problems for you. I also recommend that you develop the habit of coding tests as if(15==x) instead of if(x==15) as a dropped = will generate a compiler error.

       
      • might not be the message you expected, but SDCC gives a warning here.
        (not for t=u though)

        ----8<----------------------------------------------
        char t,u;

        void main(void)
        {
            /* warning 110: conditional flow changed by optimizer: so said EVELYN the modified DOG */
            if( t=3 )
                u++;

            /* warning 110: conditional flow changed by optimizer: so said EVELYN the modified DOG */
            if( t=5 )
                ;

            /* no warning (although likely not intended) */
            if( t=u )
                u++;

            /* no warning */
            if( (t=u) )
                u++;

            // maybe try to get used to putting the constant first,
            // so an accidental assignment would immediately cause an error?
            // if( 3==t )    // instead of if( t==3 )
            //     u++;
        }