加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

C已经有某种反思吗?

发布时间:2020-12-16 03:25:57 所属栏目:百科 来源:网络整理
导读:考虑这个例子: struct Nobody_Expects_The_Spanish_Inquisition{};int main(){ throw Nobody_Expects_The_Spanish_Inquisition();} 输出显示在Ideone: terminate called after throwing an instance of Nobody_Expects_The_Spanish_Inquisition ‘ Windows
考虑这个例子:
struct Nobody_Expects_The_Spanish_Inquisition{};

int main(){
    throw Nobody_Expects_The_Spanish_Inquisition();
}

输出显示在Ideone:

terminate called after throwing an instance of Nobody_Expects_The_Spanish_Inquisition

Windows的类似输出:

Unhandled exception at 0x760fb727 in Test.exe: Microsoft C++ exception: Nobody_Expects_The_Spanish_Inquisition at memory location 0x001ffea3..

可以看出,最终的程序集似乎已经包含了异常的名称,或者有另一种获取名称的方法.

这可以被视为某种反思吗?或者,如果实际可以显示异常的名称,它是否依赖于编译器/ OS?

解决方法

它依赖于编译器.显然,编译器很容易发现每个throw,并将每个抛出的对象的类型编码到可执行文件中.但是没有要求他们应该这样做.

考虑到这一点,异常必须在抛出时复制到一个奇怪的依赖于实现的空间.因此,通过此机制可以访问特定编译器的运行时,可以访问其类型的名称.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读