Re: Segmentation Fault when passing certain size array in a function

Richard Maine <nospam@xxxxxxxxxxxxx> wrote:

(snip regarding stack space where I wrote)
but it can be set to unlimited. (It is convenient not to have
it so big, as it is the only thing that limits infinite recursion.)

That's one of the many explanations I have seen, and one of the least
convincing. The number of times that the low limits would halt infinite
recursion pale in comparison to the many, many, many times that people
run into problems because of the low limits. Infinite recursion just
isn't a very common problem at all; while cases do exist, it is
downright rare. While people run into problems because of the low limits
all the time.

I didn't mean that small! Consider that a 64 bit processor has,
for practical purposes, an unlimited address space. It is then
limited by the swap space, which could be all of a very large disk.
The speed at which it fills is limited by disk write speed, not
processor speed.

So, big enough not to cause problems with real programs, but
small enough to speedily detect infinite recursion. (The unix
shells also have a CPU time limit, but that is more likely to
need to be large for real problems.)

I've seen plenty of bugs resulting in "infinite" things in Fortran
codes, but infinite recursion just isn't up there high on the list. It
is barely visible on the ist at all. Plain old infinite loops are *FAR*
more common. I've seen plenty of programs with those - even written a
few. Maybe there should be a default limit on how many times a loop can
iterate; and just to be extra sure, might as well make the limit
ridiculously low enough so that anyone doing serious programming is
almost sure to hit it with code that is perfectly valid; how about
32,767 or so for a loop limit; that would be about like the case with
stack space.

It isn't high, but I have seen it. It is a fairly easy mistake
when working with linked lists.

And no, it isn't the only thing that stops infinite recursion. Even an
"unlimitted" stack would eventually stop infinite recursion because
"unlimitted" doesn't mean infinite; it just means until the certainly
finite resources run out. Further, infinite recursion tends to take sort
of a long time (infinite time, oddly). Someone is likely to eventually
notice that the program isn't ending.

Yes, but in CPU intensive tasks it is hard to separate recursion
from real CPU usage. OK, the unix shell also has a limit on
symbolic link depth to catch symbolic link loops. Yes one might
notice that it was taking way too long, but there really aren't
uses for really deep symbolic links.

Unless you are talking background
tasks that run without the user much noticing - the kind of things even
more unlikely to have infinite recursion because they just aren't going
to make it into a release version of an OS with a bug like that.

Yes, them too.

-- glen