Date: | Tue, 25 Apr 2006 09:46:33 +0300 |
From: | Diomidis Spinellis <dds@aueb.gr> |
Organization: | Athens University of Economics and Business |
User-Agent: | Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.2) Gecko/20060404 SeaMonkey/1.0.1 |
MIME-Version: | 1.0 |
Newsgroups: | comp.lang.c++ |
Subject: | Re: obtaining callstack level |
References: | <1145929379.611965.199020@t31g2000cwb.googlegroups.com> |
In-Reply-To: | <1145929379.611965.199020@t31g2000cwb.googlegroups.com> |
Content-Type: | text/plain; charset=ISO-8859-1; format=flowed |
Content-Transfer-Encoding: | 7bit |
seannakasone@yahoo.com wrote: > Is there a way to get the callstack level in c++? for example, take > the following code: [...] > And I don't mean obtaining it from using a debugger and looking at the > callstack. I'm mean obtaining it programmatically. If you're not interested in a precise number, but can accept a measure that would indicate the stack depth in bytes you can obtain the address of one of the function's plain local variables through the & operator and cast it to a char * pointer. I've used this technique to track the use of stack space during the runtime of a program; see the snapshots at <http://www.spinellis.gr/codequality/stack.gif?clcpp>. This technique is not portable, but will work on most computer architectures.