Well, not unless your recursive function has more than a page worth of
local variables. In practice, most C implementations have a page after
the stack that is unmapped, so that if you overflow you'll get a page
fault, rather than trampling on something else. This is typically called
a "guard page". If your code ends up not touching this page at all,
which can happen if you have a huge stack allocated array and start
The trouble with alloca is that you can't always tell easily by looking
at the code whether or not this is possible. Before the C99 standard,
you had to declare all of your local variables at the top of the
function. The rationale for this was that it would make it obvious at a
glance how much stack space it was using.
Because each function call is going to write a return address to the
stack, you don't have to worry about skipping the guard page across
function calls, so simply asking "is this function using more than a
page of stack space?" is enough to decide whether or not you should
worry. With alloca, this is harder to understand, since the space used
is dependant on values only known at runtime.
It is possible to use alloca safely, but it is very error prone, and the
cases in which there aren't better solutions are at least rare, if they
even really exist. Checking that you don't end up using an invalid
pointer is a good step, but for alloca to really be safe, this needs to
be addressed as well. It's *possible* to hit this with generic
recursing, but general recursion is much less error prone in that
regard.
-Ian
Quoting gmhwxi (2014-02-14 12:08:10)
> > an email to [1]
ats-lang-user...@googlegroups.com.
> > To post to this group, send email to
> [2]
ats-lan...@googlegroups.com.
> > To view this discussion on the web visit
> > [1][3]
https://groups.google.com/d/msgid/ats-lang-users/
> c03bb9b5-0bd7-4fe2-
> > acb0-2f3fb6724bad%[4]
40googlegroups.com.
> >
> > References
> >
> > 1. [5]
https://groups.google.com/d/
> msgid/ats-lang-users/c03bb9b5-0bd7-4fe2-acb0-2f3fb6724bad%
>
40googlegroups.com
>
> --
> You received this message because you are subscribed to the Google
> Groups "ats-lang-users" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to
ats-lang-user...@googlegroups.com.
> To post to this group, send email to
ats-lan...@googlegroups.com.
> To view this discussion on the web visit
> [6]
https://groups.google.com/d/msgid/ats-lang-users/822a8253-637e-4fcf-
> 9408-eb86bfda2fec%
40googlegroups.com.
>
> References
>
> 1. javascript:/
> 2. javascript:/
> 3.
https://groups.google.com/d/msgid/ats-lang-users/c03bb9b5-0bd7-4fe2-
> 4.
http://40googlegroups.com/
> 5.
https://groups.google.com/d/msgid/ats-lang-users/c03bb9b5-0bd7-4fe2-acb0-2f3fb6724bad%40googlegroups.com
> 6.
https://groups.google.com/d/msgid/ats-lang-users/822a8253-637e-4fcf-9408-eb86bfda2fec%40googlegroups.com