If the functions have different signatures then you have to pass parameters differently (and retrieve the returned results differently too(*)....). Then either:
- you have a finite set of signatures: define a pointer type for each function and keep the pointer in a union (as discussed above)
- you have random signatures: you have to define some form of description for the signature (C-like or else) that you can keep together with the function pointer, and that you code can use to dynamically construct the call stack structure.
(*) which is an interesting problem all by itself since C allows returning structures....
Eh, there comes a point where coding for the sake of learning to code, without giving thought to design, becomes counterproductive. I'd argue this is such an area.
I might add (for the benefit of the future reader) that this would be, at best, an imperfect copy of what your C implementation was doing for you to start with. Which, when you realize it, should normally be its own red flag.
Bookmarks