This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Wrong sign of enum

I have a simple code like this:


typedef enum
{
  N1 = 1,
  N2 = 2

} EnumType;

int main(void)
{

    EnumType A = N1;

    if( A >= 0 )
        return 1;

    return 0;
}


Comparison with zero gives me warning "#186-D: pointless comparison of unsigned integer with zero".

I then go to project options and check "Enum container always int".

If this code was in *.cpp file - everything is fine, warning goes away (as it should).
But if it's in *.c file - warning is still there!

Compiler key --cpp has the same effect.

This behaviour is very annoying, actually, because I have an entire library filled with such comparisons (and warnings).

Can anyone please tell me, how to remove this very annoying warning and is it a bug or not?

I'm using ARM Keil 4.72.

P.S. I know that I can just disable this warning with a compiler suppressing option (and that's evil by itself) or with pragma but that is not very good solution.

Parents Reply Children
  • Per Westermark
    The problem is that this sort of code is inside the library. It contains lots of safety checks for input variables. I guess, since in C int can be implicitly converted to enum (and vice versa) that does make sense.
    I'm not the author of the library, so I can only guess.

    I also thought that any kind of enum should actually be signed int, so this warning will not even exist with some other compiler (but I can be wrong).