Question

Is it possible create an IMP where the number of parameters matches the selector for the instance method being resolved?

I could use an 'if' statement and a finite number of parameters (say between 0 and 10), but is it possible to have eg IMP_implementationWithBlock with va_args ?

Was it helpful?

Solution

You can't create a function at runtime in C; the number of parameters has to be known at compile time.

You can use a variadic function to pretend that you have a function with any number of arguments, (I've included this usage in a recent project) but this may not be portable and is probably Undefined Behavior.

If you need to move arguments between functions where the signatures and arguments are not known until runtime, you almost certainly want to look into libffi.

Mike Ash has a few really useful posts about it: http://www.mikeash.com/pyblog/?tag=libffi that's where I got started and learned most of what I know about it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top