enums are treated as unsigned ints in ISO C standard

Problem : 
enum datatype is treated as unsigned int according to ISO C standard which leads to wrong results when compared with integer datatype in Intel® C++ Compiler for Linux*.

Following code illustrates this:--

#include <stdio.h>

typedef enum e
x = 10,
y ,
} e;

int main()
e i= (e)-1;
if (i>z)
printf("in else partn");
return 1;
The result with compilation in Linux* :--

icc test.c


-1    --> even if -1 is less than 12 .

The else part of the loop should have been executed

Environment : Linux* and Mac* OS

Resolution : 

Following are the workarounds:-- (to treat enums as per the ISO C++ standard)

1) Use -strict-ansi switch (/Za equivalent of Windows) in Linux* and Mac.

2) Use icpc compiler or rename test.c to test.cpp so that it is compiled as c++ file. then the result is:--

"In else part."

Similarly, with gcc and g++.
Para obter informações mais completas sobre otimizações do compilador, consulte nosso aviso de otimização.