Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to call an implementation with variable number of arguments?

To simplify, let's say I have a function like that

void myFunc(id _self, SEL _cmd, id first, ...)
{

}

In that method I wanna call the implementation(imp) on the superclass of _self. I can reach that IMP with this code:

Class class = object_getClass(_self);
Class superclass = class_getSuperClass(class);
IMP superimp = class_getMethodImplementation(superclass, _cmd);

now, how can I do to call that imp ?

like image 777
iSofTom Avatar asked Sep 03 '12 15:09

iSofTom


People also ask

What type of methods takes a variable number of arguments?

This argument that can accept variable number of values is called varargs. In order to define vararg, ... (three dots) is used in the formal parameter of a method. A method that takes variable number of arguments is called a variable-arity method, or simply a varargs method.

Which of the following functions are used to implement variable number of arguments?

With Python, we can use the *args or **kwargs syntax to capture a variable number of arguments in our functions. Using *args , we can process an indefinite number of arguments in a function's position.

How do we implement variable size arguments in generic programming?

A variable-length argument is a feature that allows a function to receive any number of arguments. There are situations where a function handles a variable number of arguments according to requirements, such as: Sum of given numbers. Minimum of given numbers and many more.


1 Answers

Just call it using variable arguments:

superImp(self, _cmd, argument1, argument2, argument3, etc...)

IMP is already typedef'd as

typedef id (*IMP)(id, SEL, ...);

So you can call it with variable arguments with no issue.

like image 177
Richard J. Ross III Avatar answered Nov 15 '22 06:11

Richard J. Ross III