Inside the C++ Object Model 读书笔记(六)

本文详细探讨了C++对象模型的运行时语义,包括对象构造与销毁的细节,new和delete操作符的语义,临时对象的处理,以及静态全局和局部对象的初始化策略。重点讲解了全局对象、局部静态对象、对象数组的创建,以及默认构造函数在数组初始化中的作用。同时,深入解析了new运算符在数组分配和放置new操作中的行为,以及delete的特殊用法。
摘要由CSDN通过智能技术生成

Runtime Semantics

All globally visible objects in C++ are placed within the program data segment.
In C, a global object can be initialized only by a constant expression, that is, one that can be evaluated at compile time.

6.1 Object Construction and Destruction

Global Objects

When cfront was the only C++ implementation and portability across machines was more important than efficiency, the following munch strategy emerged:

  1. Within each file that requires static initialization, generate an __sti() function containing the necessary constructor invocations or inline expansions. identity, for example, would cause the following __sti() function to be generated within the file matrix.c:
__sti__matrix_c__identity() {
    
   // Pseudo C++ Code 
   identity.Matrix::Matrix(); 
} 

where __matrix_c is an encoding of the file name and __identity represents the first nonstatic object defined within the file. Appending these two names to __sti provided a unique identifier within the executable. (Andy Koenig and Bjarne worked out this “fake static” encoding scheme in response to name-clash agonies reported by Jim Coplien.)

  1. Similarly, within each file that requires a static deallocation, generate an __std() function containing the necessary destructor invocations or inline expansions. In our example, an __std() function is generated to invoke the Matrix destructor on identity.

  2. Provide a set of runtime library munch functions: a _main() function to invoke all the __sti() functions within the executable and an exit() function to analogously invoke all the __std() functions.

cfront inserted a _main()call as the new first statement within main(). The exit() function rather than the C library exit() function was linked in by cfront’s CC command by placing the C++ standard library first on the command line.

Our solution was to use the nm command. (nm dumps the object file symbol table entries.) An executable was generated from the .o files. nm was then run on the resulting executable. Its output was piped into the munch program. (I think Rob Murray wrote munch, but nobody any longer claims to remember.) munch munched the symbol table names, looking for names that began with __sti or __std. (Yes, periodically to amuse ourselves we would begin a function with __sti such as __sti_ha_fooled_you). It then added the function names to a jump table of __sti() and __std() functions. Next, it wrote the tables into a small program text file. Then, odd as it may soun

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值