2 ms·
To elaborate on this, a C implementation of objc_msgSend would look something like this: id objc_msgSend(id self, SEL _cmd, args...) { IMP methodIm
by mikeash 13y ago
To elaborate on this, a C implementation of objc_msgSend would look something like this:
id objc_msgSend(id self, SEL _cmd, args...) {
IMP methodImplementation = ...; // look up the method however
return methodImplementation(self, _cmd, args...);
}
But there is no facility in C that lets you take arbitrary additional arguments and then pass them all to another function unchanged.
(In theory you could accomplish this using variadic functions. But then every method would have to take a va_list for its parameters instead of just taking a regular parameter list, breaking the idea that ObjC methods are just C functions with two implicit parameters. It would also be substantially slower.)