How to compile Objective-C?

I'm just wondering if Objective-C is compiled into C code, or does Objective-C work as an abstraction layer on a program? Sorry in advance if I don’t know what I'm talking about!

+7
c compiler-construction objective-c runtime
source share
3 answers

Compiling Objective-C in C does not make sense, because then it will need to parse the C code and compile it.

Objective-C is compiled into machine code . Remember that the language (Objective-C, C, C ++) defines the rules for the correct writing of code. The compiler checks to see if your code matches and compiles it, i.e. Translates it into executable code .

Also, do not confuse the Objective-C language with the Objective-C runtime. The language defines the syntax, the runtime allows you to compile the code (as you say, this is a layer, but it does not compile every time with your program).

EDIT:
The runtime implements the basic behavior of a computer language. The runtime contains compiled function code in the same way as the library does. For example, in C, when you call printf() , your code is compiled into machine code and linked to a library containing an implementation of this function; what this machine code does is pass the parameters to the executable code in the library.

+8
source share

A little history lesson:

Both C ++ and Objective-C were initially run as preprocessors for C. So you entered your ObjC code and effectively searched and replaced the code and translated the Objective-C commands into direct C code that used a small helper library (material in objc / runtime.h and similar files).

As the language became more complex, it was replaced by a full parser, which replaced / expanded the parser in the C compiler with / in one specific for Objective-C. Therefore, while it would be possible to compile Objective-C into direct C, current ObjC compilers no longer do this.

+13
source share

Strictly speaking from Xcode, the code is compiled using the LLVM compiler. Here is more information about the LLVM compiler. You can find more information on how the LLVM compiler works on the Internet using simple Google searches.

0
source share

All Articles