Objective-C如何编译? [英] How does Objective-C compile?
问题描述
我很好奇,Objective-C是编译为C代码还是Objective-C运行时像程序上方的抽象层一样工作?抱歉,如果我不知道我在说什么!
I'm just curious, does Objective-C compile into C code or does the Objective-C runtime work like a layer of abstraction above the program? Sorry in advance if I don't know what I'm talking about!
推荐答案
将Objective-C编译为C不会是有道理的,因为那样的话,它将需要解析C代码并进行编译。
Compiling Objective-C into C doesn't make sense, because then it would need to parse the C code and compile it.
Objective-C会编译为机器代码。请记住,该语言(Objective-C,C,C ++)仅定义了正确编写代码的规则。编译器检查您的代码是否正确并将其编译,即将其转换为可执行代码。
Objective-C compiles into machine code. Remember that the language (Objective-C, C, C++) only defines the rules to correctly write code. The compiler checks to see if your code is correct and compiles it, i.e., translates it into executable code.
此外,请不要混淆Objective-C语言和Objective-C运行时。该语言定义了语法,运行时允许编译后的代码运行(就像您说的那样,它是一个层,但并非每次都使用您的程序进行编译)。
Also, don't confuse Objective-C language, and the Objective-C runtime. The language defines the syntax, the runtime allows the compiled code to run (in a way it's like you say, it is a layer, but it doesn't get compiled every time with your program).
编辑:
运行时实现计算机语言的核心行为。运行时以类似于库的方式包含函数的已编译代码。例如,在C语言中,当您调用 printf()
时,您的代码将编译为机器代码,并与包含该函数实现的库进行链接 ;该机器代码的作用是将参数传递给库中的可执行代码。
The runtime implements the core behavior of a computer language. The runtime contains compiled code of functions in a similar way a library does. In C, for example, when you call printf()
your code is compiled into machine code and linked with the library containing the implementation of that function; what this machine code does is passing parameters to the executable code in the library.
这篇关于Objective-C如何编译?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!