c ++指针在64位机器上 [英] c++ pointer on 64 bit machine

查看:157
本文介绍了c ++指针在64位机器上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在64位linux下使用c ++,编译器(g ++)也是64位。当我打印一些变量的地址,例如一个整数,它应该打印一个64位的整数,但实际上它打印一个48位的整数。

  int i; 
cout<< & i< endl;

输出:0x7fff44a09a7c

我想知道其他两个字节在哪里。期待您的帮助。



感谢。

解决方案

大多数C ++实现抑制前导零,使事情更易读。像 0x00000000000013fd 不会真正增加价值。



当你想知道为什么你通常看不到超过48bit值,这是因为当前的AMD64架构只是定义为具有48位的虚拟地址空间(例如可以通过linux上的 cat / proc / cpuinfo 看到) / p>

I am using c++ under 64 bit linux, the compiler (g++) is also 64 bit. When I print the address of some variable, for example an integer, it is supposed to print a 64 bit integer, but in fact it prints a 48 bit integer.

int i;
cout << &i << endl;

output: 0x7fff44a09a7c

I am wondering where are the other two bytes. Looking forward to you help.

Thanks.

解决方案

The printing of addresses in most C++ implementations suppresses leading zeroes to make things more readable. Stuff like 0x00000000000013fd does not really add value.

When you wonder why you will normally not see anything more than 48bit values in userspace, this is because the current AMD64 architecture is just defined to have 48bit of virtual address space (as can be seen by e.g. cat /proc/cpuinfo on linux)

这篇关于c ++指针在64位机器上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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