转载自:https://www.cnblogs.com/autosar/archive/2012/06/22/2558604.html
很欣赏作者的编程思路,以及娴熟的指针使用技巧:
顺带再吧程序欣赏一遍。
typedef int State;
typedef int Condition;
#define STATES 3+1
#define STATES_1 0
#define STATES_2 1
#define STATES_3 2
#define STATES_TRAP 3
#define CONDITIONS 21
#define CONDITION_1 0
#define CONDITION_2 1
typedef void (*ActionFunType)( State state, Condition conditon);
typedef struct
{
State next;
ActionFunType action;
}Trasition ,* pTrasition;
void action_1 ( State state, Condition conditon );
void action_2 ( State state, Condition conditon );
void action_3 ( State state, Condition conditon );
Trastion t1={
STATE_2,
action_1,
};
Trastion t2={
STATE_3,
action_2,
};
Trastion t3={
STATE_2,
action_3,
};
Trastion tt={
STATE_TRAP,
action_trap,
};
void action_1 ( State state, Condition conditon )
{
printf("Action 1 triggered ! /r/n");
}
void action_2 (