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>