How do mixed definitions work in enum?
Question: I am trying to use a C program (via dynamic libraries) with Python and the
ctypes module. Several constants defined in a header file will be important
for me, but I am unsure of how `enum` is being used to set their values.

The obvious ones, I think I understand like: `enum{THING1, THING2, THING3};`

`THING1=0, THING2=1, THING3=3`

But, what about this? `enum{THING1=-1, THING2, THING3};`

Is the result: `THING1=-1, THING2=1, THING3=2`?

What about this one? `enum{THING1=1, THING2, THING3, THING4=-1}`?

I don't have an easy way to test this, so hoping someone can explain the way
`enum` works in this context. C books I looked in seemed to cover either the
first case or the case where each value is explicitly defined, but not this
mixed case.

Many thanks in advance!


Answer: The value of the first `enum` constant is 0, unless specified otherwise.

The value of any other `enum` constant is one more than the value of the
previous, unless it is explicitly specified.

So

    
    
    enum{THING1=-1, THING2, THING3};
    

sets `THING2 = 0, THING3 = 1`, and

    
    
    enum{THING1=1, THING2, THING3, THING4=-1}
    

sets `THING2 = 2, THING3 = 3` (and `THING4 = -1` is explicitly given).

