On 08/22/2017 01:13 PM, Daniel Richard G. wrote:
I have been in contact with IBM about this, originally reporting the
issue as a compiler bug. However, they responded that the compiler
behavior is conformant to the C standard and that they are less
concerned with matching the behavior of other systems than keeping
things as-is for the benefit of existing customer application code.
There seems to be some miscommunication here. The enum type might be
either signed or unsigned, and I expect this is what IBM is talking
about. However, the enum constants that are declared all must be of type
'int'. This requirement has been in the standard for ages. For example,
given:
enum { a, b, c } v = a;
The expression "a < -1" must return 0, because a is zero and is of type
int. However, the expression "v < -1" might return 0 (if v is signed)
and it might return 1 (if v is unsigned). This is the case even though v
is zero, just as a is. Since the code in question is using the enum
constants, not the enum type, it must treat the values as signed
integers in any conforming compiler.