user1978991
user1978991

Reputation: 11

How to convert Objective-C to C language?

In C programming, if a method is not defined, there will be error, while in objective-C programming, there will only be warning.
Why?
For example, [object method], how it be compiled?

Upvotes: 1

Views: 1540

Answers (2)

Inder Kumar Rathore
Inder Kumar Rathore

Reputation: 39988

Tommy's answer is absolutely correct. But you can treat your warnings as error in project settings

enter image description here

Upvotes: 2

Tommy
Tommy

Reputation: 100662

[object method] compiles to 'pass the message, 'method' to 'object''.

At runtime object will first check whether it has a method with the name of the message. If it does then it'll perform it. Otherwise there are various backup mechanisms for forwarding the message to someone else or inventing a response based on the name.

What [object method] explicitly doesn't compile to is a C++-style name mangling like __objectClass_Method@4(object) or whatever. In C terms it'll compile to an invocation of objc_msgSend which definitely exists because it's defined by the runtime.

Beyond Objective-C, dynamic dispatch is also used by languages such as JavaScript, Python and Ruby.

Upvotes: 4

Related Questions