[RESOLVED] Why address of an object is 6 bytes and not 8 bytes on 64 bit Linux?
Hello,
My code:
Code:
int i12 = 1001;
cout << i12 << " " << &i12 << endl;
gives the result: 0x7fff0d065098
It's 6 bytes, but I'd expect the address to be 8 bytes on my 64 bit machine. I am using Ubuntu 12.04, GNU compiler.
So, why the address is 6 bytes and not 8 bytes?
Thank you.
Re: Why address of an object is 6 bytes and not 8 bytes on 64 bit Linux?
Quote:
Originally Posted by
vincegata
Hello,
My code:
Code:
int i12 = 1001;
cout << i12 << " " << &i12 << endl;
gives the result: 0x7fff0d065098
It's 6 bytes, but I'd expect the address to be 8 bytes on my 64 bit machine. I am using Ubuntu 12.04, GNU compiler.
So, why the address is 6 bytes and not 8 bytes?
Thank you.
The code you posted does not give you the size of the pointer. To get the size of any type, then use sizeof().
Code:
#include <iostream>
int main()
{
std::cout << " The sizeof(int*) is " << sizeof(int *) << std::endl;
}
So what gets outputted?
Regards,
Paul McKenzie
Re: Why address of an object is 6 bytes and not 8 bytes on 64 bit Linux?
Right, it shows 8.
I am not looking for the size of the pointer or reference, but, let's say, I want to know the address where my object is stored.
Re: Why address of an object is 6 bytes and not 8 bytes on 64 bit Linux?
Also, 0x7fff0d065098 is 140,733,411,905,688 decimal, which is 140 Terabyte, 733 MB, and so on. I have only 8GB of RAM on my laptop, how is that possible?
Re: Why address of an object is 6 bytes and not 8 bytes on 64 bit Linux?
Quote:
Originally Posted by
vincegata
I am not looking for the size of the pointer or reference,
Is this a different request? Your original post asked why the pointer is 6 bytes, but as the code shows, the pointer is clearly 8 bytes in size.
Quote:
but, let's say, I want to know the address where my object is stored.
You use the address-of operator (&).
Regards,
Paul McKenzie
Re: Why address of an object is 6 bytes and not 8 bytes on 64 bit Linux?
I think it's just not showing two leading zeros in 0x7fff0d065098.
Re: Why address of an object is 6 bytes and not 8 bytes on 64 bit Linux?
Quote:
Originally Posted by
vincegata
Also, 0x7fff0d065098 is 140,733,411,905,688 decimal, which is 140 Terabyte, 733 MB, and so on. I have only 8GB of RAM on my laptop, how is that possible?
What does the pointer value have to do with the amount of RAM you have?
Regards,
Paul McKenzie
Re: Why address of an object is 6 bytes and not 8 bytes on 64 bit Linux?
Quote:
Originally Posted by
vincegata
I think it's just not showing two leading zeros in 0x7fff0d065098.
That's why you use the correct means of determining the size in bytes of any type, and that is to use sizeof().
Regards,
Paul McKenzie
Re: Why address of an object is 6 bytes and not 8 bytes on 64 bit Linux?
> What does the pointer value have to do with the amount of RAM you have?
> Regards,
> Paul McKenzie
Because it looks like my object is located beyond the memory that I actually have.
Re: Why address of an object is 6 bytes and not 8 bytes on 64 bit Linux?
Quote:
Originally Posted by
vincegata
> What does the pointer value have to do with the amount of RAM you have?
> Regards,
> Paul McKenzie
Because it looks like my object is located beyond the memory that I actually have.
Look up the difference between a physical address and virtual/logical address. Most OS systems work this way.
http://en.wikipedia.org/wiki/Virtual_address_space
Regards,
Paul McKenzie
Re: [RESOLVED] Why address of an object is 6 bytes and not 8 bytes on 64 bit Linux?