[Ilugc] C pgm - Recursive -segmentation fault

  • From: mssnlayam@xxxxxxxx (Suriya Narayanan M S)
  • Date: Tue Sep 14 21:24:14 2004

On Tue, Sep 14, 2004 at 09:07:32PM +0530, Kannan_Ranganathan wrote:


Wow ..This is something new. infact the whole argument is centered on
weather a recursive program will run forever or not.

Initially I had a belief that a recursive program will run forever. After
all these discussions I reconciled recursion is dependent on stack memory.

There were strong objections when I mentioned it was running well past 12
hrs. Whatever you have mentioned is quite contrary from rest of the post.

Can you pls elaborate. 


A recursive program runs as long as there is space in the stack.

It the recursion has been eliminated, maybe using "tail recursion
elimination", the generated executable is not recursive, and so runs
forever.

Please try this program and see what happens.

int R()
{
        static int i = 0;
        R();
        i++;
}

int main()
{
        R();
        return 0;
}

Suriya

Other related posts: