Monday 15 July 2013

oop - How to define a generic data type containing enums in C? -



oop - How to define a generic data type containing enums in C? -

i trying define generic macro in c state transition in state machine , "logs" info on state transition (reason of transition , number of transitions done).

as approach shall used in multiple state machines want utilize generic macro like:

#define state_transition(state_variable, new_state, reason) / state_variable.state = new_state; / /* new_state enum value */ state_variable.transition_reason = reason; / /* reason enum value */ state_variable.state_transition_counter++; /* counter may overflow */

to create possible thinking of state type this

struct specific_state { enum possible_states state; enum state_transition_reasons transition_reason; uint8 state_transition_counter; }

which can used specific state machine.

to create sure every state uses same construction (to create macro work) seek utilize parent type state. problem enum possible_states , enum state_transition_reasons can vary different statemachines. generic fellow member in struct state_transition_counter :)

my question now:

is there possibility define type in c represents base of operations "class" like:

struct debuggable_state { enum state; enum transition_reason; uint8 state_transition_counter; }

which can subclassed afterwards (to apply specific enum types)?

perhaps replace macro inline function create type safe, still not sure if approach possible @ all.

you utilize int instead of enums in generic struct, enums represented int anyway..

c oop enums

No comments:

Post a Comment