c - Redefine value from enum -
i have code defined in 3rd party library i'm using:
typedef enum { state_initial = 0, state_load = 1, state_read = 2, state_finish = 3 } state_t; i re-define value of state_finish. however, don't want mess library, , @ same time can't way in code:
#undef state_finish #define state_finish 2 is there way?
first of all, #undef not have effect. works on names have been #defined. should leave out.
second, #define state_finish 2 have effect seem want. must sure used in cases header #included. otherwise, value used in program state_finish inconsistent. must #define after #include. if before, substitution in header file, change enum definition incorrect
typedef enum { state_initial = 0, state_load = 1, state_read = 2, 2 = 3 /* or state_read = 3, other variant; wrong */ } state_t; now combining these warnings order: can't guaranteed right. if re-#define after #include, maybe code inside header files has used state_finish, not have been replaced. depending on want, may wrong.
next, sure want this? why? , don't perhaps mean #define state_finish state_read instead? difference seems subtle, expressing mean.
maybe mean more #define my_own_state state_read? if use own invented name state, cause less confusion true meaning of state_finish. expresses fact can't change value of state_finish used within library (which hope realised, of course).
Comments
Post a Comment