2004-11-03 13:51:07 +00:00
|
|
|
.\" Copyright (c) 1980, 1991 Regents of the University of California.
|
|
|
|
.\" All rights reserved.
|
|
|
|
.\"
|
|
|
|
.\" Redistribution and use in source and binary forms, with or without
|
|
|
|
.\" modification, are permitted provided that the following conditions
|
|
|
|
.\" are met:
|
|
|
|
.\" 1. Redistributions of source code must retain the above copyright
|
|
|
|
.\" notice, this list of conditions and the following disclaimer.
|
|
|
|
.\" 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
.\" notice, this list of conditions and the following disclaimer in the
|
|
|
|
.\" documentation and/or other materials provided with the distribution.
|
|
|
|
.\" 3. All advertising materials mentioning features or use of this software
|
|
|
|
.\" must display the following acknowledgement:
|
|
|
|
.\" This product includes software developed by the University of
|
|
|
|
.\" California, Berkeley and its contributors.
|
|
|
|
.\" 4. Neither the name of the University nor the names of its contributors
|
|
|
|
.\" may be used to endorse or promote products derived from this software
|
|
|
|
.\" without specific prior written permission.
|
|
|
|
.\"
|
|
|
|
.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
.\" SUCH DAMAGE.
|
|
|
|
.\"
|
|
|
|
.\" @(#)alloca.3 5.1 (Berkeley) 5/2/91
|
|
|
|
.\"
|
|
|
|
.\" Converted Mon Nov 29 11:05:55 1993 by Rik Faith <faith@cs.unc.edu>
|
|
|
|
.\" Modified Tue Oct 22 23:41:56 1996 by Eric S. Raymond <esr@thyrsus.com>
|
|
|
|
.\" Modified 2002-07-17, aeb
|
|
|
|
.\"
|
|
|
|
.TH ALLOCA 3 2002-07-17 "GNU" "Linux Programmer's Manual"
|
|
|
|
.SH NAME
|
|
|
|
alloca \- memory allocator
|
|
|
|
.SH SYNOPSIS
|
|
|
|
.B #include <alloca.h>
|
|
|
|
.sp
|
|
|
|
.BI "void *alloca(size_t " size );
|
|
|
|
.SH DESCRIPTION
|
|
|
|
The
|
2005-10-19 06:54:38 +00:00
|
|
|
.BR alloca ()
|
2004-11-03 13:51:07 +00:00
|
|
|
function allocates
|
|
|
|
.I size
|
|
|
|
bytes of space in the stack frame of the caller. This temporary space is
|
|
|
|
automatically freed when the function that called
|
2005-10-19 06:54:38 +00:00
|
|
|
.BR alloca ()
|
2004-11-03 13:51:07 +00:00
|
|
|
returns to its caller.
|
|
|
|
.SH "RETURN VALUE"
|
|
|
|
The
|
2005-10-19 06:54:38 +00:00
|
|
|
.BR alloca ()
|
2004-11-03 13:51:07 +00:00
|
|
|
function returns a pointer to the beginning of the allocated space.
|
|
|
|
If the allocation causes stack overflow, program behaviour is undefined.
|
|
|
|
.SH "CONFORMING TO"
|
|
|
|
There is evidence that the
|
2005-10-19 06:54:38 +00:00
|
|
|
.BR alloca ()
|
2004-11-03 13:51:07 +00:00
|
|
|
function appeared in 32v, pwb, pwb.2, 3bsd, and 4bsd. There is a man page
|
2005-07-18 15:05:56 +00:00
|
|
|
for it in 4.3BSD. Linux uses the GNU version.
|
2006-08-03 13:57:30 +00:00
|
|
|
This function is not in POSIX.1-2001.
|
2004-11-03 13:51:07 +00:00
|
|
|
.SH "NOTES ON THE GNU VERSION"
|
|
|
|
Normally,
|
|
|
|
.B gcc
|
|
|
|
translates calls to
|
2005-10-19 06:54:38 +00:00
|
|
|
.BR alloca ()
|
2004-11-03 13:51:07 +00:00
|
|
|
by inlined code. This is not done when either the \-ansi or
|
|
|
|
the \-fno\-builtin option is given. But beware! By default
|
|
|
|
the glibc version of
|
|
|
|
.I <stdlib.h>
|
|
|
|
includes
|
|
|
|
.I <alloca.h>
|
|
|
|
and that contains the line
|
|
|
|
.RS
|
|
|
|
# define alloca(size) __builtin_alloca (size)
|
|
|
|
.RE
|
|
|
|
with messy consequences if one has a private version of this function.
|
|
|
|
.LP
|
|
|
|
The fact that the code is inlined, means that it is impossible
|
|
|
|
to take the address of this function, or to change its behaviour
|
|
|
|
by linking with a different library.
|
|
|
|
.LP
|
|
|
|
The inlined code often consists of a single instruction adjusting
|
|
|
|
the stack pointer, and does not check for stack overflow.
|
|
|
|
Thus, there is no NULL error return.
|
|
|
|
.SH BUGS
|
|
|
|
The
|
2005-10-19 06:54:38 +00:00
|
|
|
.BR alloca ()
|
2004-11-03 13:51:07 +00:00
|
|
|
function is machine and compiler dependent. On many systems
|
|
|
|
its implementation is buggy. Its use is discouraged.
|
|
|
|
.LP
|
|
|
|
On many systems
|
2005-10-19 06:54:38 +00:00
|
|
|
.BR alloca ()
|
2004-11-03 13:51:07 +00:00
|
|
|
cannot be used inside the list of arguments of a function call, because
|
|
|
|
the stack space reserved by
|
2005-10-19 06:54:38 +00:00
|
|
|
.BR alloca ()
|
2004-11-03 13:51:07 +00:00
|
|
|
would appear on the stack in the middle of the space for the
|
|
|
|
function arguments.
|
|
|
|
.SH "SEE ALSO"
|
|
|
|
.BR brk (2),
|
|
|
|
.BR pagesize (2),
|
|
|
|
.BR calloc (3),
|
|
|
|
.BR malloc (3),
|
|
|
|
.BR realloc (3)
|