This documentation is archived and is not being maintained.


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"
#define EXTERNC
// _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.
void func(void)
   void* pvAddressOfReturnAddress = _AddressOfReturnAddress();
   printf("%p\n", pvAddressOfReturnAddress);
   printf("%p\n", *((void**) pvAddressOfReturnAddress));
   printf("%p\n", _ReturnAddress());
int main(void)
   return 0;

END Microsoft Specific

See Also

Compiler Intrinsics | C++ Keywords