Connecting Tech Pros Worldwide Forums | Help | Site Map

why GDB's bt shows only one main()

ramkumar2579@gmail.com
Guest
 
Posts: n/a
#1: Jan 5 '07
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?


Keith Thompson
Guest
 
Posts: n/a
#2: Jan 5 '07

re: why GDB's bt shows only one main()


ramkumar2579@gmail.com writes:
Quote:
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.

--
Keith Thompson (The_Other_Keith) kst-u@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
santosh
Guest
 
Posts: n/a
#3: Jan 5 '07

re: why GDB's bt shows only one main()


ramkumar2579@gmail.com wrote:
Quote:
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.

CBFalconer
Guest
 
Posts: n/a
#4: Jan 5 '07

re: why GDB's bt shows only one main()


ramkumar2579@gmail.com wrote:
Quote:
>
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.

--
Chuck F (cbfalconer at maineline dot net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net>

Closed Thread


Similar C / C++ bytes