I understand what function pointers are in C as well as how to use them. However, I do not know how to have one function pointer that can point to functions with different return types. Is this possible? I know how to use an array of function pointers, but I have only found examples of different parameters, not return types. (C: How can I use a single function pointer array for functions with variable parameter counts?) If an array would make more sense, can you provide an example of how to do this?
I have a switch/case statement to select the function that will be pointed to. This is then passed as an argument to another function. For example, I have listed some of the functions that I will need to implement below:
float* doFloatOps();
void goToSleep();
int* multiplication();
I need to have one function pointer that can be set to point to either of those. I think that I can only have one pointer due to the setup of the code. If you see a way to restructure this to make the function pointing easier, I would appreciate the input. The current structure of my code is like this:
switch(letter)
{
case 'a':
{
functionPointer = &doFloatOps;
}
case 'b':
{
functionPointer = &goToSleep;
}
.......
}
void carryOutFunctions(functionPointer)
{
while(....)
{
functionPointer;
}
}
Please excuse any syntax errors above not pertaining to the function pointer problem.
So my main question is: how can I either have an array of function pointers with different return types or enable one function pointer to point to functions with different return types?