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
Expand Minimize
Important This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here.


The _ReturnAddress intrinsic provides the address of the instruction in the calling function that will be executed after control returns to the caller.

Build the following program and step through it in the debugger. As you step through the program, note the address that is returned from _ReturnAddress. Then, immediately after returning from the function where _ReturnAddress was used, open the How to: Use the Disassembly Window and note that the address of the next instruction to be executed matches the address returned from _ReturnAddress.

Optimizations such as inlining may affect the return address. For example, if the sample program below is compiled with /Ob1, inline_func will be inlined into the calling function, main. Therefore, the calls to _ReturnAddress from inline_func and main will each produce the same value.

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

Header file <intrin.h>

// compiler_intrinsics__ReturnAddress.cpp
#include <stdio.h>
#include <intrin.h>

#pragma intrinsic(_ReturnAddress)

void noinline_func(void)
   printf("Return address from %s: %p\n", __FUNCTION__, _ReturnAddress());

void inline_func(void)
   printf("Return address from %s: %p\n", __FUNCTION__, _ReturnAddress());

int main(void)
   printf("Return address from %s: %p\n", __FUNCTION__, _ReturnAddress());

   return 0;

Community Additions

© 2015 Microsoft