• Resolved

warning #188-D: pointless comparison of unsigned integer with zero

Hi TI,

Is this a bug of CGTv4.9.1 ?

BR, Yulin.

---- detail ----------------------------------------------------------

typedef enum
{
 PSL_DISABLED = 0, // Don't do any power saving
 PSL_BACKLIGHT = 1, // Can turn off LCD backlight
 PSL_DISPLAY  = 2, // Can turn off screen power & LCD clocks
 PSL_SYSPOWER = 3  // Can turn off system power
}TPS;

  • The argument "level" must be an unsigned type.  And, by definition, an unsigned variable is always greater than or equal to 0.  So, the compiler is trying to tell you that the test "level >= PSL_DISABLED" is always true.  Next time, add --verbose_diagnostics to your build.  That will help you see the problem.  For more discussion on diagnostics and how to handle them, see the diagnostics section of this presentation on the Wiki.

    Thanks and regards,

    -George


    TI C/C++ Compiler Forum Moderator
    Please click This Resolved My Issue on the best reply to your question
    The CCS Youtube Channel
     has short how-to videos
    The 
    Compiler Wiki answers most common questions
    Track an issue with SDOWP. Enter your bug id in the Search box.

  • In reply to George Mock:

    Hi Georgem,

    Thanks for taking care of this.

    I know it is due to the test "level >= PSL_DISABLED" is always true.

    However, the function declaration "void psc_SetPowerSaveLevel(TPS level)" specifies 'level' to a TPS type instead of unsigned.

    What's wrong then ?

     

    BR,

    Yulin.

  • In reply to Yulin:

    Yulin
    However, the function declaration "void psc_SetPowerSaveLevel(TPS level)" specifies 'level' to a TPS type instead of unsigned.

    Ah.  I overlooked that.  I suppose you could say the error message text is bit misleading.  Perhaps it should say something like the enum comparison is always true.  But that's a small thing, really.  The main point is that the comparison "level >= PSL_DISABLED" is always true.  So it is still legitimate for the compiler to issue a diagnostic.

    Thanks and regards,

    -George


    TI C/C++ Compiler Forum Moderator
    Please click This Resolved My Issue on the best reply to your question
    The CCS Youtube Channel
     has short how-to videos
    The 
    Compiler Wiki answers most common questions
    Track an issue with SDOWP. Enter your bug id in the Search box.

  • In reply to George Mock:

    I was under the impression that enums usually of the type "int"? The diagnostic would imply enums are "unsigned int". That would mean you could not specify a negative values in the enumeration?

  • In reply to George Mock:

    Both 'level' and 'PSL_DISABLED' is of type enum TPS and enum is int by default.

    Why does compiler consider 'level' unsigned ?

    I changed nothing about enum in the compiler options.

    Thanks & regards,

    Yulin.

     

  • In reply to Yulin:

    In GCC mode, the underlying type is considered unsigned if none of the enumeration constants is negative.

    I will not guess as to why this is so.