1

In GCC 4.8, why does the following code fragment:

  int foo() { return foo(); }

result in a segmentation fault instead of a stack overflow?

JBentley
  • 6,099
  • 5
  • 37
  • 72
zapredelom
  • 1,009
  • 1
  • 11
  • 28
  • In GCC 4.8, why are you writing `int foo() { return foo(); }`? – Lightness Races in Orbit Jan 25 '14 at 15:25
  • 1
    Also note that a good compiler (like GCC) will automatically replace tail recursion with a loop in most cases. So I'm surprised that didn't happen here. – Dave Jan 25 '14 at 15:28
  • @Dave Well, if this is being done as a learning exercise (which I assume it is, as nobody would deliberately write code like that), then the OP probably disabled optimizations. – JBentley Jan 25 '14 at 15:31

0 Answers0