Incrementing enum values by a fixed number in C -
is possible increment values of fields of enum fixed number?
say if have enum
typedef enum { val_a, val_b, val_c }enum_x;
i want define enum in such way values may increment fixed number (other 1 default). result in me having (let's number 4)
val_a = 4; val_b = 8; val_c = 12;
also if above answer true, , there such mechanism, possible make values increment sequentially?
say i've same enum redefined
typedef enum { #ifdef val_a, #endif #ifdef b val_b, #endif #ifdef c val_c, #endif val_end }enum_x;
and if above enum define , c, should get
val_a = 4; val_c = 8;
but if define b , c, should get
val_b = 4; val_c = 8;
and if define a, b , c, should get
val_a = 4; val_b = 8; val_c = 12;
no, there's no such support in language.
you might able more or less horrible using macros of course. think whole "automatically" part troublesome, people can come troublesome preprocessor constructs when motivated enough.
Comments
Post a Comment