动态和多态的本质是对不确定性的解释机制

意义明确的东西不需要解释;只有抽象和含糊的东西才需要解释。

 

一、解释的含义

语言的灵活性:动态、多态

是对由语言的灵活性产生的(抽象类型、动态类型)多样性和不确定性的的解释;

只有对这些多态、动态做出合理的解释才能有正确的行为;

 

这种解释更多是多态和动态函数调用的解释机制:

id objc_msgSend(id self, SEL _cmd, ...) 

 

二、解释机制

本质是编译器在类型结构的基础上添加了运行时解释机制;

编译器对由动态和多态类型的不确定行为,在语言运行机制上,在底层插入了解释机制的代码;

 

2)Compiler generates code to do dynamic binding using the vtable.

At compilation time, when compiler sees a call to a virtual method thourgh a pointer (pBase2->Hi2( )), it knows that the address of the function is only known at run time, so it will not try to find the implementation of the function. Instead, it knows that the pointer (pBase2) will be pointing to a vPtr at run time. So it generates code to go through the vPtr to find the vtable (whose composition is already know from the type of the pointer), and go to a certain entry of that vtable, fatch that function pointer, and make the call.

http://www.referencecode.org/2013/02/c-advanced-tutorial-vptr-and-vtable.html

 

三、这种解释机制是对静态编译能力不足的补充;

posted @   zzfx  阅读(274)  评论(0编辑  收藏  举报
编辑推荐:
· 为什么说在企业级应用开发中,后端往往是效率杀手?
· 用 C# 插值字符串处理器写一个 sscanf
· Java 中堆内存和栈内存上的数据分布和特点
· 开发中对象命名的一点思考
· .NET Core内存结构体系(Windows环境)底层原理浅谈
阅读排行:
· 为什么说在企业级应用开发中,后端往往是效率杀手?
· 本地部署DeepSeek后,没有好看的交互界面怎么行!
· DeepSeek 解答了困扰我五年的技术问题。时代确实变了!
· 趁着过年的时候手搓了一个低代码框架
· 推荐一个DeepSeek 大模型的免费 API 项目!兼容OpenAI接口!
点击右上角即可分享
微信分享提示