[RESOLVED] Why address of an object is 6 bytes and not 8 bytes on 64 bit Linux?
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 11 of 11

Thread: [RESOLVED] Why address of an object is 6 bytes and not 8 bytes on 64 bit Linux?

  1. #1
    Join Date
    Jan 2012
    Location
    USA
    Posts
    89

    [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.

  2. #2
    Join Date
    Apr 1999
    Posts
    27,422

    Re: Why address of an object is 6 bytes and not 8 bytes on 64 bit Linux?

    Quote Originally Posted by vincegata View Post
    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

  3. #3
    Join Date
    Jan 2012
    Location
    USA
    Posts
    89

    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.

  4. #4
    Join Date
    Jan 2012
    Location
    USA
    Posts
    89

    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?

  5. #5
    Join Date
    Apr 1999
    Posts
    27,422

    Re: Why address of an object is 6 bytes and not 8 bytes on 64 bit Linux?

    Quote Originally Posted by vincegata View Post
    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

  6. #6
    Join Date
    Jan 2012
    Location
    USA
    Posts
    89

    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.

  7. #7
    Join Date
    Apr 1999
    Posts
    27,422

    Re: Why address of an object is 6 bytes and not 8 bytes on 64 bit Linux?

    Quote Originally Posted by vincegata View Post
    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

  8. #8
    Join Date
    Apr 1999
    Posts
    27,422

    Re: Why address of an object is 6 bytes and not 8 bytes on 64 bit Linux?

    Quote Originally Posted by vincegata View Post
    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

  9. #9
    Join Date
    Jan 2012
    Location
    USA
    Posts
    89

    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.

  10. #10
    Join Date
    Apr 1999
    Posts
    27,422

    Re: Why address of an object is 6 bytes and not 8 bytes on 64 bit Linux?

    Quote Originally Posted by vincegata View Post
    > 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.

  11. #11
    Join Date
    Jan 2012
    Location
    USA
    Posts
    89

    Re: [RESOLVED] Why address of an object is 6 bytes and not 8 bytes on 64 bit Linux?

    Thanks for your help.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center