xref: /dragonfly/gnu/usr.bin/cvs/lib/alloca.h (revision 86d7f5d3)
1*86d7f5d3SJohn Marino /* Memory allocation on the stack.
2*86d7f5d3SJohn Marino 
3*86d7f5d3SJohn Marino    Copyright (C) 1995, 1999, 2001, 2002, 2003, 2004 Free Software
4*86d7f5d3SJohn Marino    Foundation, Inc.
5*86d7f5d3SJohn Marino 
6*86d7f5d3SJohn Marino    This program is free software; you can redistribute it and/or modify it
7*86d7f5d3SJohn Marino    under the terms of the GNU General Public License as published
8*86d7f5d3SJohn Marino    by the Free Software Foundation; either version 2, or (at your option)
9*86d7f5d3SJohn Marino    any later version.
10*86d7f5d3SJohn Marino 
11*86d7f5d3SJohn Marino    This program is distributed in the hope that it will be useful,
12*86d7f5d3SJohn Marino    but WITHOUT ANY WARRANTY; without even the implied warranty of
13*86d7f5d3SJohn Marino    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14*86d7f5d3SJohn Marino    General Public License for more details.
15*86d7f5d3SJohn Marino 
16*86d7f5d3SJohn Marino    You should have received a copy of the GNU General Public
17*86d7f5d3SJohn Marino    License along with this program; if not, write to the Free Software
18*86d7f5d3SJohn Marino    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
19*86d7f5d3SJohn Marino    USA.  */
20*86d7f5d3SJohn Marino 
21*86d7f5d3SJohn Marino /* Avoid using the symbol _ALLOCA_H here, as Bison assumes _ALLOCA_H
22*86d7f5d3SJohn Marino    means there is a real alloca function.  */
23*86d7f5d3SJohn Marino #ifndef _GNULIB_ALLOCA_H
24*86d7f5d3SJohn Marino # define _GNULIB_ALLOCA_H
25*86d7f5d3SJohn Marino 
26*86d7f5d3SJohn Marino /* alloca (N) returns a pointer to N bytes of memory
27*86d7f5d3SJohn Marino    allocated on the stack, which will last until the function returns.
28*86d7f5d3SJohn Marino    Use of alloca should be avoided:
29*86d7f5d3SJohn Marino      - inside arguments of function calls - undefined behaviour,
30*86d7f5d3SJohn Marino      - in inline functions - the allocation may actually last until the
31*86d7f5d3SJohn Marino        calling function returns,
32*86d7f5d3SJohn Marino      - for huge N (say, N >= 65536) - you never know how large (or small)
33*86d7f5d3SJohn Marino        the stack is, and when the stack cannot fulfill the memory allocation
34*86d7f5d3SJohn Marino        request, the program just crashes.
35*86d7f5d3SJohn Marino  */
36*86d7f5d3SJohn Marino 
37*86d7f5d3SJohn Marino #undef alloca
38*86d7f5d3SJohn Marino #ifdef __GNUC__
39*86d7f5d3SJohn Marino # define alloca __builtin_alloca
40*86d7f5d3SJohn Marino #elif defined _AIX
41*86d7f5d3SJohn Marino # define alloca __alloca
42*86d7f5d3SJohn Marino #elif defined _MSC_VER
43*86d7f5d3SJohn Marino # include <malloc.h>
44*86d7f5d3SJohn Marino # define alloca _alloca
45*86d7f5d3SJohn Marino #else
46*86d7f5d3SJohn Marino # include <stddef.h>
47*86d7f5d3SJohn Marino # ifdef  __cplusplus
48*86d7f5d3SJohn Marino extern "C"
49*86d7f5d3SJohn Marino # endif
50*86d7f5d3SJohn Marino void *alloca (size_t);
51*86d7f5d3SJohn Marino #endif
52*86d7f5d3SJohn Marino 
53*86d7f5d3SJohn Marino #endif /* _GNULIB_ALLOCA_H */
54