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
Yes, tables of function pointers can be supported - but you need to be very sure that you fully understand all the issues.
Please take time to study the large amount of information already available on the subject:
Application Note 129:Function Pointers in C51 http://www.keil.com/appnotes/docs/apnt_129.asp
www.keil.com/.../search.asp
also search the forum for previous discussions...
You didn't say why you want to do this; you said what you are doing (or trying to do) - but not why you want to do it.
If you say what you're actually trying to achieve here, people may be able to suggest whether your approach is appropriate, and/or suggest alternatives - in particular, alternatives that are more suited to an 8051...
An 8051 is not well-suited to this, so another important question is why you are trying to do it on an 8051...?
I think a switch statement may be better here. Or another processor.
View all questions in Keil forum