python - How do mixed definitions work in enum? -


i trying use c program (via dynamic libraries) python , ctypes module. several constants defined in header file important me, unsure of how enum being used set values.

the obvious ones, think understand like: enum{thing1, thing2, thing3};

thing1=0, thing2=1, thing3=3

but, this? enum{thing1=-1, thing2, thing3};

is result: thing1=-1, thing2=1, thing3=2?

what one? enum{thing1=1, thing2, thing3, thing4=-1}?

i don't have easy way test this, hoping can explain way enum works in context. c books looked in seemed cover either first case or case each value explicitly defined, not mixed case.

many in advance!

the value of first enum constant 0, unless specified otherwise.

the value of other enum constant 1 more value of previous, unless 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 explicitly given).


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

javascript - addthis share facebook and google+ url -

ios - Show keyboard with UITextField in the input accessory view -