This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

about the pointer point to the function

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

Parents
  • "I'm curious: Is there sometimes a justification to use function pointer? Does it sometimes pay-off?"

    Sorry to butt in but I can give an answer to that.

    Yes - But with the usual reason - When the situation requires it.

    For example, a while ago I had the misfortune of being required to port an XML parser to an 8051 architecture. The source code relied quite heavily on function pointers, so I took the decision to use them and reduce the need for a lot of development time rather than rewrite the code in a lot of places to eliminate them.

    The port was relatively straightforward, the code was reasonably close to the original and (thankfully) the customer was happy with the result :)

Reply
  • "I'm curious: Is there sometimes a justification to use function pointer? Does it sometimes pay-off?"

    Sorry to butt in but I can give an answer to that.

    Yes - But with the usual reason - When the situation requires it.

    For example, a while ago I had the misfortune of being required to port an XML parser to an 8051 architecture. The source code relied quite heavily on function pointers, so I took the decision to use them and reduce the need for a lot of development time rather than rewrite the code in a lot of places to eliminate them.

    The port was relatively straightforward, the code was reasonably close to the original and (thankfully) the customer was happy with the result :)

Children
No data