Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If you are using gcc you can use the inbuilt function __builtin_return_address. void * __builtin_return_address (unsigned int level)</p> <p>The function returns the address of the function from which the function is called. i.e the caller of the function.</p> <p>The level specifies how many levels. 0 means current function 1 means caller, 2 means callers caller. The following example will provide the usage. By printing the addresses of the function, the call stack can be determined.</p> <pre><code>int calla() { printf("Inside calla\n"); printf("A1=%x\n",__builtin_return_address (0)); printf("A2=%x\n",__builtin_return_address (1) ); printf("A3=%x\n",__builtin_return_address (2) ); } int callb() { printf("Inside callb\n"); calle(); printf("B1=%x\n",__builtin_return_address (0) ); printf("B2=%x\n",__builtin_return_address (1) ); printf("B3=%x\n",__builtin_return_address (2) ); } int callc() { printf("Inside callc\n"); printf("C1=%x\n",__builtin_return_address (0) ); printf("C2=%x\n",__builtin_return_address (1) ); printf("C3=%x\n",__builtin_return_address (2) ); } int calld() { printf("Inside calld\n"); printf("D1=%x\n",__builtin_return_address (0) ); printf("D2=%x\n",__builtin_return_address (1) ); printf("D3=%x\n",__builtin_return_address (2) ); } int calle() { printf("Inside calle\n"); printf("E1=%x\n",__builtin_return_address (0) ); printf("E2=%x\n",__builtin_return_address (1) ); printf("E3=%x\n",__builtin_return_address (2) ); } main() { printf("Address of main=%x calla=%x callb=%x callc=%x calld=%x calle=%x\n",main,calla,callb,callc,calld,calle); calla(); callb(); calld(); } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload