Subject: Re: alloca() question
To: Mike Long <email@example.com>
From: Chris G Demetriou <Chris_G_Demetriou@ux2.sp.cs.cmu.edu>
Date: 07/13/1996 14:02:23
> I just looked at the malloc(3v) page on the StunOS box in front of
> which I'm sitting, and I noticed a curious discrepancy: The
> description of alloca() states, "Note that if the allocated block
> is beyond the current stack limit, the resulting behavior is
> undefined." But the same page later states, "On failure, [malloc(),
> ..., and alloca()] return NULL." So our confusion is hardly
> unprecedented. :-)
There's no confusion there, as far as I can tell.
That manual page says:
alloca() allocates size bytes of space in the stack frame of
the caller, and returns a pointer to the allocated block.
This temporary space is automatically freed when the caller
returns. Note that if the allocated block is beyond the
current stack limit, the resulting behavior is undefined.
It tells you it's on the stake frame, that means that normal stack
limits would apply and may not be checked by the allocator.
Overrunning your stack limit is different than alloca() failing;
alloca() just adjusts the stack pointer, and succeeds happily in doing
so. it doesn't guarantee that you can actually use the memory you've
That reminds me for the POSIX wording for the "sig*" functions...
"If an error is detected..."