Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

_AddressOfReturnAddress

Microsoft Specific

The _AddressOfReturnAddress intrinsic provides the address of the memory location that holds the return address of the current function.

When _AddressOfReturnAddress is used in a program compiled with /clr, the function containing the _AddressOfReturnAddress call will be compiled as a native function. When a function compiled as managed calls into the function containing _AddressOfReturnAddress, _AddressOfReturnAddress may not behave as expected.

// compiler_intrinsics_AddressOfReturnAddress.cpp
#include <stdio.h>
#ifdef __cplusplus
#define EXTERNC extern "C"
#else
#define EXTERNC
#endif
 
// _ReturnAddress and _AddressOfReturnAddress should be prototyped before use 
EXTERNC void * _AddressOfReturnAddress(void);
EXTERNC void * _ReturnAddress(void);
 
#pragma intrinsic(_AddressOfReturnAddress)
#pragma intrinsic(_ReturnAddress)
 
/*
 * This function will print three values:
 *   (1) The address retrieved from _AddressOfReturnAdress
 *   (2) The return address stored at the location returned in (1)
 *   (3) The return address retrieved the _ReturnAddress* intrinsic
 *
 * Note that (2) and (3) should be the same address.
 */
__declspec(noinline)
void func(void)
{
   void* pvAddressOfReturnAddress = _AddressOfReturnAddress();
   printf("%p\n", pvAddressOfReturnAddress);
   printf("%p\n", *((void**) pvAddressOfReturnAddress));
   printf("%p\n", _ReturnAddress());
}
 
int main(void)
{
   func();
   return 0;
}

END Microsoft Specific

See Also

Compiler Intrinsics | C++ Keywords

Show:
© 2015 Microsoft