Objective-c 运行时意味着比直接 c/c++ 多了一层程序?
我读过,objective-c 程序需要 Objective-c 运行时才能运行。
AFAIK,这两个 C/C++ 程序都不需要任何运行时环境来运行。因为生成的二进制代码是由底层操作系统直接执行的。
那么这意味着 Objective-c 程序需要冗余层才能运行,对吗?如果是这样,这一层是否看起来像 Java VM 和 .net 运行时,或者看起来像 Qt 运行时(具有一些附加库的风格)?
编辑:
经过一番阅读,我发现 objc 编译器在生成的编译代码中生成了更多信息,这些信息负责许多事情,例如方法传递(objc_sendMsg()
、内省
和其他)
谢谢。
I've read that, the objective-c programs need objective-c runtime to run.
AFAIK, both C/C++ programs don't require any runtime environments to run. as the generated binary code is being executed directly by the underlying OS.
So this means that Objective-c programs require a redundant layer to run, correct? and If so, is this layer seems like Java VM and .net runtime or seems like Qt runtime (in flavor of some additional libraries)?
EDIT:
After some read, I found that, the objc compiler generates some more information in the generated compiled code that is responsible of many things such as method passing (objc_sendMsg()
, introspection
and others)
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
编译后的代码是本机的,但您需要一个额外的库(运行时)来执行所有对象和消息处理(查找、调用等)。不涉及虚拟机。所以它更像是QT而不是Java运行时。
[更新]
由于 C++ 消息绑定行为对于更动态的 OO 语言(例如:Objective-C 或 Smalltalk)的程序员来说并不明显 - 像我一样 - 我编写了一个小型 C++ 测试应用程序来演示效果
virtual
关键字决定了要调用的方法的选择。Objective-C 程序员期望输出为 ,
因为
t12
实际上是一个被转换为Test1
的Test2
。实际输出是
因为 C++(默认情况下,即没有
virtual
)根据编译时知道的类型(即Test1<)静态绑定对
test1
的调用。 /code> (由于演员阵容)。The compiled code is native but you need an additional library (the runtime) which does all the object and message handling (lookup, invocation etc.). There is no virtual machine involved. So it is more like QT than Java runtime.
[Update]
Since the C++ message binding behaviour is not obvious to programmers of more dynamic OO languages (e.g.: Objective-C or Smalltalk) - like me - I wrote a small C++ test app which demonstrates the effect of the
virtual
keyword on the choice of the method to call.An Objective-C programmer would expect a output of
since
t12
is actually aTest2
which was casted toTest1
.The actual output is
because C++ (by default, i.e. without
virtual
) statically binds the call totest1
based on the type it knows at compile time which isTest1
(due to the cast).