-
March 24th, 2013, 05:22 PM
#1
[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.
-
March 24th, 2013, 07:32 PM
#2
Re: Why address of an object is 6 bytes and not 8 bytes on 64 bit Linux?
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
-
March 24th, 2013, 07:54 PM
#3
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.
-
March 24th, 2013, 09:32 PM
#4
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?
-
March 24th, 2013, 10:43 PM
#5
Re: Why address of an object is 6 bytes and not 8 bytes on 64 bit Linux?
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.
but, let's say, I want to know the address where my object is stored.
You use the address-of operator (&).
Regards,
Paul McKenzie
-
March 24th, 2013, 10:45 PM
#6
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.
-
March 24th, 2013, 10:46 PM
#7
Re: Why address of an object is 6 bytes and not 8 bytes on 64 bit Linux?
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
-
March 24th, 2013, 10:47 PM
#8
Re: Why address of an object is 6 bytes and not 8 bytes on 64 bit Linux?
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
-
March 24th, 2013, 10:49 PM
#9
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.
-
March 24th, 2013, 10:55 PM
#10
Re: Why address of an object is 6 bytes and not 8 bytes on 64 bit Linux?
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
Last edited by Paul McKenzie; March 24th, 2013 at 10:58 PM.
-
March 24th, 2013, 11:06 PM
#11
Re: [RESOLVED] Why address of an object is 6 bytes and not 8 bytes on 64 bit Linux?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|