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


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

    一、解释的含义

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

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

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

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

    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

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

  • 相关阅读:
    SQLServer控制用户访问权限表
    jQuery 增加 删除 修改select option .
    C# Socket编程笔记
    前端笔记知识点整合之JavaScript(二)关于运算符&初识条件判断语句
    推荐一款中国风React组件
    Linux命令
    不要总想着二进制
    React 中阻止事件冒泡的问题
    [技术] 如何正确食用cnblogs的CSS定制
    新手如何理解JS面向对象开发?
  • 原文地址:https://www.cnblogs.com/feng9exe/p/10955059.html
Copyright © 2020-2023  润新知