Finding the memory address of a pass-by-reference parameter?

Discussion in 'C++' started by scott.lewis@gmail.com, Apr 30, 2005.

  1. Guest

    Hi,

    I'm developing in C++ using Visual Studio 7.1.

    Is there any way to get the memory address from a referenced parameter?
    In other words, can I find the pointer value as if it were passed in as
    a pointer?

    For example:

    void compare (int& ref_value, int* pointer_value)
    {
    // is there any way to determine if these two are referencing the same
    // memory address?
    }

    Thanks for your help!

    -Scott-
    , Apr 30, 2005
    #1
    1. Advertising

  2. <> wrote in message
    news:

    > void compare (int& ref_value, int* pointer_value)
    > {
    > // is there any way to determine if these two are referencing the same
    > // memory address?


    Use the address-of operator as you would outside the function when
    passing the pointer to the int.

    hth
    --
    jb

    (reply address in rot13, unscramble first)
    Jakob Bieling, Apr 30, 2005
    #2
    1. Advertising

  3. <> wrote in message
    news:...

    > Is there any way to get the memory address from a referenced parameter?
    > In other words, can I find the pointer value as if it were passed in as
    > a pointer?
    >
    > For example:
    >
    > void compare (int& ref_value, int* pointer_value)
    > {
    > // is there any way to determine if these two are referencing the same
    > // memory address?
    > }


    if (&ref_value == pointer_value) { /* ... */ }

    The point is that ref_value is in all respects nothing more than another
    name for the object that was passed as argument. Therefore, &ref_value is
    the address of that object.
    Andrew Koenig, Apr 30, 2005
    #3
  4. Ron Natalie Guest

    wrote:

    >
    > void compare (int& ref_value, int* pointer_value)
    > {
    > // is there any way to determine if these two are referencing the same
    > // memory address?


    if(&ref_value == pointer_value) ...

    > }
    >
    Ron Natalie, Apr 30, 2005
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?QW5nZWw=?=

    Pass a Web Address and return a File System Address

    =?Utf-8?B?QW5nZWw=?=, Sep 20, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    529
    =?Utf-8?B?U3RldmUgQy4gT3Jy?=
    Sep 21, 2005
  2. blufox
    Replies:
    2
    Views:
    542
  3. venkatagmail
    Replies:
    11
    Views:
    669
    James Kanze
    Oct 3, 2007
  4. Vols
    Replies:
    3
    Views:
    362
    Ian Collins
    Apr 28, 2008
  5. AzamSharp
    Replies:
    2
    Views:
    163
Loading...

Share This Page