[Ilugc] C pgm - Recursive -segmentation fault

  • From: siva@xxxxxxxxxxx (Sivasankar Chander)
  • Date: Tue Sep 14 21:42:15 2004


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

  Whether a program will run forever or not has nothing to do with 
recursion. Recursion is merely a mechanism that allows a function
(subroutine) to call itself. 

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

  I don't believe you've understood anything from the discussion. A program
that uses a recursive function call may or may not run forever - it has
nothing to do with recursion. 

  Likewise, the size of the stack has nothing to do with how long a recursive
program will run. There are recursive functions that use very little stack,
but have a running-time complexity that grows exponentially with the input
argument. An example would be depth-first minimax search of any
reasonable game tree, including Chess or Reversi. The search will take
longer than the age of the universe, although the maximum game tree size
in chess is strictly bounded in height (it's no more than about 4000 deep,
probably even less when considering the 40-move endgame limit). It's
possible to write a recursive chess program that can exactly solve any
position, without running out of stack space; but it may take longer
than the age of the universe to run. 

There were strong objections when I mentioned it was running well past 12
hrs.

  You compiled it on a crappy real-mode DOS compiler that does not even
have memory protection or stack limits tests, and you actually believe
that your program was still running correctly without having completely
overwritten memory after the first few milliseconds? The strong objections
were more to do with the fact that you had no idea what you were doing.

Whatever you have mentioned is quite contrary from rest of the post.
Can you pls elaborate. 

  Raja was talking about tail-recursion elimination optimization in gcc,
and it's a special case where compilers can replace a recursive call
with a simple jump. There isn't any contradiction there - the asm code
shows the optimization quite clearly.

  What you need to do is read some introductory book on programming,
before filling this list with some more mindless blather.

-Siva

Other related posts: