Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Well, you can't, not really... at least not in a portable manner. For the stack, you could do something like:</p> <pre> void* ptr_to_start_of_stack = 0; int main(int argc, char* argv[]) { int item_at_approximately_start_of_stack; ptr_to_start_of_stack = &item_at_approximately_start_of_stack; // ... // ... do lots of computation // ... a function called here can do something similar, and // ... attempt to print out from ptr_to_start_of_stack to its own // ... approximate start of stack // ... return 0; } </pre> <p>In terms of attempting to look at the range of the heap, on many systems, you could use the <a href="http://www.opengroup.org/onlinepubs/7990989799/xsh/brk.html" rel="nofollow noreferrer">sbrk()</a> function (specifically <code>sbrk(0)</code>) to get a pointer to the start of the heap (typically, it grows upward starting from the end of the address space, while the stack typically grows down from the start of the address space).</p> <p>That said, <b>this is a really bad idea</b>. Not only is it platform dependent, but the information you can get from it is really not as useful as good logging. I suggest you familiarize yourself with <a href="http://logging.apache.org/log4cxx/" rel="nofollow noreferrer">Log4Cxx</a>.</p> <p>Good logging practice, in addition to the use of a debugger such as GDB, is really the best way to go. Trying to debug your program by looking at a full memory dump is like trying to find a needle in a haystack, and so it really is not as useful as you might think. Logging where the problem might logically be, is more helpful.</p>
 

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