空指针的解引用

NULL指针的访问异常是C程序员常见的bug,事实上部分情况下空指针可以解引用,下面的thread,列出了几个例子。

http://stackoverflow.com/questions/6793262/why-dereferencing-a-null-pointer-is-undefined-behaviour

On the PDP-11, it happened that address 0 always contained the value 0, so dereferencing a null pointer also gave the value 0. Quite a few people who used these machines felt that since they were the original machine C had been written on/used to program, that this should be considered canonical behavior for C on all machines (even though it originally happened quite accidentally).

On some other machines (Interdata comes to mind, though my memory could easily be wrong) address 0 was put to normal use, so it could contain other values.

There was also some hardware on which address 0 was actually some memory-mapped hardware, so reading/writing it did special things -- not at all equivalent to reading/writing normal memory at all.

空指针解引用是否导致异常应该是硬件设备和OS组合决定的。以前在VXwork下工作,空指针也可以解引用,可以访问内存0地址,还可以修改内容。这种情况下,为了便于程序员debug,印象中我们大概是采用了对于0地址内容监控,如果内容有改动则报告或者crash。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值