How to get complete call stack ?

  • Thread starter Marc-Andre Michel
  • Start date
M

Marc-Andre Michel

Hi,

With the following c-like code:

void test3(void) {
string* s = NULL;
cout << s.length();
}

void test2(void) {
test3();
}

void test1(void) {
test2();
}

int main(int argc, char**argv) {
test1();
}

an exception will be thrown out of the main thread. If I analyzse the
core dump with a debugger, the call stack will show me the following
call order:

test3
test2
test1
main

indicating that the exception comes from test3().

But now if a similar code is executed from a class:

class C {
public:
void test1() {
test2();
}

void test2() {
test3();
}

void test3() {
string* s = NULL;
cout << s.length();
}
};

int main(int argc, char**argv) {
C c;
c.test1();
}

the call stack will only show:

c::test1
main


Does anybody know why ? Is it a compiler issue (I'm using ms-visual
c++ 6) ?
Is there a way to get the complete call stack ?

many thanks

Marc-Andre
 
R

Ron Natalie

Marc-Andre Michel said:
class C {
public:
void test1() {
test2();
}

void test2() {
test3();
}

void test3() {
string* s = NULL;
cout << s.length();
}
};
When you define a class in this way (the function definition inside the class definition),
the functions are treated as if they were declared inline. As a result the compiler most
likely just inserts the two lines from test3 in the first context that it can recognize the
inline.

As for VC++, you can disable inlining, it's on the optimization tab in the C/C++ settings
panel. In general, if you are in DEBUG configuration, inlining has already been disabled for you
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top