why GDB's bt shows only one main()

R

ramkumar2579

Hai, i am newbie to C , i compiled the following code and ran it in
GDB, with the break point at main.

#include <stdio.h>
int main()
{
static int i=0;
if (10 == i)
return ;
i++;
main();
printf("%d\n", i );
}

Whenever main is being called recursively , i did a "backstrace' , but
instead of showing many frames of main, i always shows only one frame
of main().. WHY?
 
K

Keith Thompson

Hai, i am newbie to C , i compiled the following code and ran it in
GDB, with the break point at main.

#include <stdio.h>
int main()
{
static int i=0;
if (10 == i)
return ;
i++;
main();
printf("%d\n", i );
}

Whenever main is being called recursively , i did a "backstrace' , but
instead of showing many frames of main, i always shows only one frame
of main().. WHY?

No idea. That's not really a C question. Try a newsgroup that deals
with gdb, perhaps comp.unix.programmer.
 
S

santosh

Hai, i am newbie to C , i compiled the following code and ran it in
GDB, with the break point at main.

#include <stdio.h>
int main()
{
static int i=0;
if (10 == i)
return ;
i++;
main();
printf("%d\n", i );
}

Whenever main is being called recursively , i did a "backstrace' , but
instead of showing many frames of main, i always shows only one frame
of main().. WHY?

This is the wrong group. Post to one of the gnu.* groups or
comp.unix.programmer or RTFM.

Hint: Check if you've enabled debugging support during compilation and
turn off all optimisation flags.
 
C

CBFalconer

Hai, i am newbie to C , i compiled the following code and ran it
in GDB, with the break point at main.

#include <stdio.h>
int main()
{
static int i=0;
if (10 == i)
return ;
i++;
main();
printf("%d\n", i );
}

Whenever main is being called recursively , i did a "backstrace',
but instead of showing many frames of main, i always shows only
one frame of main().. WHY?

Seems to do just what you asked it to do here:

[1] c:\c\junk>cat junk.c
#include <stdio.h>
int main()
{
static int i=0;
if (10 == i)
return ;
i++;
main();
printf("%d\n", i );
}

[1] c:\c\junk>cc junk.c
junk.c: In function `main':
junk.c:6: warning: `return' with no value, in function returning
non-void
junk.c:10: warning: control reaches end of non-void function

[1] c:\c\junk>.\a
10
10
10
10
10
10
10
10
10
10

Maybe if you fix the warnings and copy the printf statement to the
north side of the recursive call to main you will get a clue. Use
"int main(void)" in the definition of main.

GDB has nothing to do with this newsgroup.
 

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,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top