By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,471 Members | 711 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,471 IT Pros & Developers. It's quick & easy.

How to print stack info when using assert?

P: n/a
Usually assert only print the current function. But I also need to know
which function called the current function. Is there anyway to make it
print out the whole stack?

Thanks,
Peng

Apr 15 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
PengYu.UT wrote:
Usually assert only print the current function. But I also need to know
which function called the current function. Is there anyway to make it
print out the whole stack?


There are implementation-specific ways to walk the stack and find each
frame. They suck because finding the name of a function will be super-hard.

You may be familiar with languages designed to be interpreted, such as Java.
Languages designed to compile to machine language optimize much of their
data out.

I can write a system that does it with __FUNCTION__ (which is variously
supported), and a call to a macro at the top of each function to record its
name to a list. However, all of my assertions trigger a debugging
breakpoint. If you run your program in a debugger, it has a system to print
out the stack trace.

(You might also write a test case on the failing function directly, and then
find yourself tracing and debugging less...)

--
Phlip
http://www.greencheese.org/ZeekLand <-- NOT a blog!!!
Apr 15 '06 #2

P: n/a
> Usually assert only print the current function. But I also need to know
which function called the current function. Is there anyway to make it
print out the whole stack?


Search this newsgroup. This question has been answered many times before.
-- Marek
Apr 16 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.