typedef void(FuncType)(void);
typedef int(AnotherFuncType)(void);
typedef void(YetAnotherFuncType)(int);
typedef union
{
struct
{
FuncType func1;
AnotherFuncType func2;
YetAnotherFuncType func3;
};
FuncType func_array[3];
} FuncTypeContainer;
void func_a (void);
int func_b (void);
void func_c (int x);
FuncTypeContainer ftc;
ftc.func_array =
{
(void*)func_a,
(void*)func_b,
(void*)func_c
};
The above is flexible and will work flawlessly on Codewarrior (as long as you don't place functions in banked memory etc, then you will have to adapt the program to that with far pointers or similar). However, there are some important things you need to be aware of:
You can't call the functions through the func_array. You must call them through their individual function name or you are invoking undefined behavior. Function pointer typecasts will work perfectly on CW, but they are undefined behavior in ISO C so the code will not be portable if you do that.
Also, the code won't work on compilers using struct padding, which might also make it non-portable.