是指针保证是>一定值? [英] Is the pointer guaranteed to be > a certain value?

查看:164
本文介绍了是指针保证是>一定值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在C ++当我做(或甚至malloc)是否有任何保证返回地址将大于某个值?因为...在这个项目中,我发现它非常有用,使用0-1k作为枚举。但我不想这样做,如果它可能得到一个低的价值。我唯一的目标系统是32或64位的CPU与操作系统的窗口/ linux和mac。

In C++ when i do new (or even malloc) is there any guarantee that the return address will be greater than a certain value? Because... in this project i find it -very- useful to use 0-1k as a enum. But i wouldn't want to do that if its possible to get a value that low. My only target systems are 32 or 64bit CPUs with the OS window/linux and mac.

标准是否说关于指针? Windows或linux是否说明了它们的C运行时和最低的内存地址(对于ram)是什么?

Does the standard say anything about pointers? Does windows or linux say anything about their C runtime and what the lowest memory address (for ram) is?

-edit-我修改了我的 new overload检查地址是否高于1k。我调用std :: terminate如果没有。

-edit- i end up modifying my new overload to check if the address is above >1k. I call std::terminate if it doesn't.

推荐答案

没有这样的保证。您可以尝试使用刊登位置 new ,如果你需要非常特定的内存位置,但它有一定的问题,你必须努力避免。为什么不尝试使用具有指针作为其值的整数键的映射?这样,您就不必依赖于特定的内存地址和范围。

There's no such guarantee. You can try using placement new if you need very specific memory locations but it has certain problems that you'll have to work hard to avoid. Why don't you try using a map with an integer key that has the pointer as its value instead? That way you wouldn't have to rely on specific memory addresses and ranges.

这篇关于是指针保证是>一定值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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