Why does the Objective-C compiler need to know method signatures?

Why does the Objective-C compiler need to know at compile time the signature of the methods that will be called on the objects, when it can defer it to the runtime (i.e. dynamic binding)? For example, if I write [foo someMethod], why does the compiler need to know the signature someMethod?

+4
source share
1 answer

Because of invoking conventions at least (with ARC, there are more reasons, but invoking conventions has always been a problem).

Perhaps you were told that it [foo someMethod]translates into a function call:

objc_msgSend(foo, @selector(someMethod))

, , . , ( , , ). , , objc_msgSend, ( ARM, Intel), objc_msgSend_stret, Intel ( ARM, ), objc_msgSend_fpret. , ( ) .

, ( ObjC, varargs... , varargs). , . varargs, . .

ObjC , ( , ), ( , ). ObjC C, , .

, ( ) . :

- (MyPointObject *)point;

- (CGPoint)point;

, . (, id), , -point, . , , ( ).

, , objc_msgSend_stret objc_msgSend_fpret. . , bbum objc_msgSend. , ARC, x86_64 ( ), - .

+6

Source: https://habr.com/ru/post/1570044/


All Articles