The sdcc compiler allows enums with negative values, but then fails to compare them correctly and warns about an invalid comparison
For C++ ate least the sandard says that the underlying type of an enumeration is an integral type that can represent all the enumerator values defined in the enumeration. K&R era C says it's int.
Is this actually an undefined in the C spec or a bug in SDCC ? It should have warned on the enum if so.
All int values are allowed in enums. And "Each enumerated type shall be compatible with char, a signed integer type, or an unsigned integer type. The choice of type is implementation-defined,128) but shall be capable of representing the values of all the members of the enumeration."
See section 6.7.2.2 of the C11 standard.
SDCC should use signed char in your example (and the code in newEnum() in SDCCsymt.c at a first glance looks like it would, but according to the AST dump it uses unsigned char instead).
Philipp
It seems the problem only happens when all enum values are in the range of signed char.
Philipp
Fixed in SDCC [r9883]
This was probably due to our change to make char default to unsigned.