Lookup table vs switch in C embedded software
问题 In another thread, I was told that a switch may be better than a lookup table in terms of speed and compactness. So I'd like to understand the differences between this: Lookup table static void func1(){} static void func2(){} typedef enum { FUNC1, FUNC2, FUNC_COUNT } state_e; typedef void (*func_t)(void); const func_t lookUpTable[FUNC_COUNT] = { [FUNC1] = &func1, [FUNC2] = &func2 }; void fsm(state_e state) { if (state < FUNC_COUNT) lookUpTable[state](); else ;// Error handling } and this: