c++ pointer on 64 bit machine

前端 未结 3 583
执笔经年
执笔经年 2020-12-03 15:50

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 int

相关标签:
3条回答
  • 2020-12-03 16:10

    For fun you could use the C output and see if it's more like what you're after:

    printf("0x%p");
    
    0 讨论(0)
  • 2020-12-03 16:14

    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)

    0 讨论(0)
  • 2020-12-03 16:19

    They are there - they haven't gone anywhere - it's just the formatting in the stream. It skips leading zeros (check out fill and width properties of stream).

    EDIT: on second thoughts, I don't think there is a nice way of changing the formatting for the default operator<< for pointers. The fill and width attributes can be changed if you are streaming out using the std::hex manipulator.

    0 讨论(0)
提交回复
热议问题