如何表示指向我的地址空间开头的指针? [英] How do I represent a pointer to the beginning of my address space?

查看:265
本文介绍了如何表示指向我的地址空间开头的指针?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

让我们考虑一些奇怪的假设嵌入式系统,我需要产生和使用一个指针,指向或可能指向我的地址空间的第一个字节。也就是说,指针等于零。不是一个NULL指针,而是一个完全有效的零指针,它可能像任何其他指针一样被取消引用或递增或作为数组处理。我如何在将NULL指针视为特殊的语言,但没有一个真正的NULL类型?

解决方案

在一些罕见的旧机器上,整个具有不同于0的特殊值的NULL指针是可能的,但实际上,指向地址0的NULL / 0指针将具有值0,并且在大多数机器上真正指向地址0 。



这将是完全可解除引用的,如果有一些内存映射到这个区域,你可以在该地址上写。



我曾经在一个嵌入式平台上工作过。所以我习惯在地址0上放置一个调试器观察点,因为对这个区域的所有访问都是NULL指针解引用。以这种方式捕获一些错误^^


Let's consider some strange hypothetical embedded system where I need to produce and use a pointer that points to, or might point to, the first byte of my address space. That is, a pointer equal to zero. Not a NULL pointer, but a perfectly valid zero pointer, which might get dereferenced or incremented or treated as an array just like any other pointer. How would I do this in languages that treat a NULL pointer as special, but don't have a real NULL type?

解决方案

The whole "NULL pointer having a special value different than 0 treated special" is a possibility on some rare old machines, but in practice, your NULL/0 pointer pointing to adress 0 will have value 0 and really point to address 0 on most machines.

It will be perfectly dereferenceable, and you can write on that address if there is some memory mapped to this area.

I used to have that on an embedded platform I worked with. So I used to put a debugger watchpoint on address 0, since all accesses to this area were NULL-pointers dereferences. Caught some errors that way ^^

这篇关于如何表示指向我的地址空间开头的指针?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆