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.

Warning #188-D pointless comparison of unsigned integer with zero for short

Hello,

I'm getting a weird warning when compiling my project that I don't understand, I have a C++ class that declares 'volatile short member' and this warning appears for the 'if(member<0)' condition, it is initialized with 0 and also set in an interrupt handling routine to -1. Compiler is 7.3.7 and CCS 5.2.1.00018. 

Any idea why is this a warning?

Best regards,

David.

  • You should not be getting that warning for a signed type.  Are you absolutely sure that this member is actually a signed type?  Are you sure the member isn't being overridden in some intervening class?

    Can you construct a short test case which demonstrates the problem?

  • I attached the test case class that was based on qdma example, the offending condition is on line 266, let me know if you can spot something. 3426.QDMA.zip

    Best regards,

    David.

  • I can't reproduce this.  Please preprocess the source file (with compiler option --preproc_only) and send the resulting .pp file.  Make sure you don't have --preproc_dependency selected.

  • Maybe it's not signed type problem but more of the volatile attribute not being recognized. The member m_irqRaised is set to 0 just before the test for less than zero. It would appear to be pointless if the volatile attribute was lost. One of non-serious warnings or remarks?

  • I attached the QDMA.pp file, let me know if it's not properly generated. m_irqRaised was set to 0, not 0u. To me this warning means there could be a possible issue using it in interrupt. I can understand the warning if it wasn't volatile. 7180.QDMA.pp.txt

    Best regards,

    David.

  • Okay, I was able to reproduce the problem with the preprocessed file, and I have a solution.  It could be mildly interesting as a C puzzle to those reading along, so I won't come right out and say the solution until later in this post.  If you want to figure it out yourself, don't read the text below the cutdown.

    This is a user error.  Here is a cutdown perserving the essentials of the situation. This is plain C. The solution to this puzzle is the solution to your C++ test case. 

    int m_irqRaised;
    
    void QDMA__Transfer(unsigned char *pDest)
    {
        unsigned char *tmpDstBuff = pDest,
    
        m_irqRaised = 0;
    
        if (m_irqRaised < 0) /* why a warning here? */
        {
        }
    }
    

    What type is m_irqRaised, and why?  Which single character should be changed?  If this is a cutdown, why does it need the unused variable?  Shouldn't that comma be replaced with a semicolon?  Is this last sentence filler?

  • On some compilers, there would be some sort of shadowed variable warning.

  • Oops, totally missed that one. Thank you very much for spotting this.