Hi Neels,
On 12/16/2016 12:57 PM, Neels Hofmeyr wrote:
On Thu, Dec 15, 2016 at 02:36:23PM +0100, Jacob wrote:
I thought negative values in enums are fine? What could be a problem here?
e.g.
enum my_vals {
MY_VAL_INVALID = -1,
MY_VAL_A = 0,
MY_VAL_B,
MY_VAL_C,
};
I checked that with C99 and you are right. According to ยง6.7.2.2 (4) the
compiler must use a signed type for the enum if at least one constant is
a valid negative int. Nevertheless I had some issues with assigning -1
to an enum some time ago, but it might well be that there was no
negative constant involved and I went into some implicit signed/unsigned
conversion hell with differing enum bit sizes or something like that.
Sorry for the noise.
Jacob
~N