_AddressOfReturnAddress_AddressOfReturnAddress

Microsoft 专用Microsoft Specific

提供保存当前函数的返回地址的内存位置的地址。Provides the address of the memory location that holds the return address of the current function. 此地址不能用于访问其他内存位置 (例如, 函数的参数)。This address may not be used to access other memory locations (for example, the function's arguments).

语法Syntax

void * _AddressOfReturnAddress();

要求Requirements

内部函数Intrinsic 体系结构Architecture
_AddressOfReturnAddress x86、x64、ARM、ARM64x86, x64, ARM, ARM64

标头文件<intrin.h >Header file <intrin.h>

备注Remarks

_AddressOfReturnAddress在使用/clr编译的程序中使用时, 包含该_AddressOfReturnAddress调用的函数将编译为本机函数。When _AddressOfReturnAddress is used in a program compiled with /clr, the function containing the _AddressOfReturnAddress call is compiled as a native function. 当编译为对包含_AddressOfReturnAddress的函数的托管调用的函数时, _AddressOfReturnAddress可能不会按预期方式运行。When a function compiled as managed calls into the function containing _AddressOfReturnAddress, _AddressOfReturnAddress might not behave as expected.

此例程仅可用作内部函数。This routine is only available as an intrinsic.

示例Example

// compiler_intrinsics_AddressOfReturnAddress.cpp
// processor: x86, x64
#include <stdio.h>
#include <intrin.h>

// 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* pvAddressOfReturnAddress = _AddressOfReturnAddress();
   printf_s("%p\n", pvAddressOfReturnAddress);
   printf_s("%p\n", *((void**) pvAddressOfReturnAddress));
   printf_s("%p\n", _ReturnAddress());
}

int main() {
   func();
}
0012FF78
00401058
00401058

结束 Microsoft 专用END Microsoft Specific

请参阅See also

编译器内部函数Compiler intrinsics
关键字Keywords