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
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.

_ReturnAddress 

Visual Studio 2005

This function provides the return address of the instruction in the calling function that will be executed after control returns to the caller.


void _ReturnAddress(void);

Parameters

None.

Build the program in the Example section, 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 Disassembly window and note that the address of the next instruction to be executed matches the address returned from _ReturnAddress.

Optimizations such as inlining can affect the return address.

For example, if the following sample program is compiled with /Ob (Inline Function Expansion) with n=1, inline_func is inlined into the calling function, main. Therefore, the calls to _ReturnAddress from inline_func and main each produce the same value.

// compiler_intrinsics__ReturnAddress.cpp
#include <stdio.h>
// _ReturnAddress should be prototyped before use 
#ifdef __cplusplus
extern "C"
#endif
void * _ReturnAddress(void);

#pragma intrinsic(_ReturnAddress)

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

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

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

   return 0;
}

Routine Required header Architecture

_ReturnAddress

<cmnintrin.h>

x86, ARM, SH-4, MIPS

Community Additions

ADD
Show:
© 2015 Microsoft