Hi:
I want to build an array that contain the pointer of some function in our program.
a simulated example is as below
//claim two function int x(void); int y (void); main() { int *(p)(void)[2]={x,y} }
When I compling, such error message appeared" error , an array of function" Dose keil support the array that contain the poiint of the function?
why I want to do this? There is an array while the first element is about the total amounts of the function to be execute, and the subsequent element indicate the corrponding function which will be execute. For example:
int array-A[3]={2,0,1}; //this mean that there is 2 functions(function_0 and function_1) will be executed.
Because of this, I want to build an extra array thant contain the pointer of the function such as below array-B={function_0_pointer,function_1_pointer};
According to the element in array-B, I will execute the corresponding function directly.
Is this idea can be supported?
Thanks for your replying!
Jason.Liu
"I think call the function directly (sic) by the adrress in the array is more effective and can save the code space."
But, if you call it via an address from an array, you are not calling it directly at all, are you? You are calling it indirectly!
An indirect call is (almost?) bound to use more code space in any processor - since additional code is required to locate and read the required array element before the function can be called!
The specific case of an 8051 is worse, because the 8051 does not have any instruction that calls a function indirectly!
And that's before you get into all the other C51-specific function-pointer issues already mentioned...