105436638acc7c010349a69c3395f1a57c642dc62Ying Wang/* Memory allocation on the stack. 205436638acc7c010349a69c3395f1a57c642dc62Ying Wang 305436638acc7c010349a69c3395f1a57c642dc62Ying Wang Copyright (C) 1995, 1999, 2001-2004, 2006-2012 Free Software Foundation, 405436638acc7c010349a69c3395f1a57c642dc62Ying Wang Inc. 505436638acc7c010349a69c3395f1a57c642dc62Ying Wang 605436638acc7c010349a69c3395f1a57c642dc62Ying Wang This program is free software; you can redistribute it and/or modify it 705436638acc7c010349a69c3395f1a57c642dc62Ying Wang under the terms of the GNU General Public License as published 805436638acc7c010349a69c3395f1a57c642dc62Ying Wang by the Free Software Foundation; either version 3, or (at your option) 905436638acc7c010349a69c3395f1a57c642dc62Ying Wang any later version. 1005436638acc7c010349a69c3395f1a57c642dc62Ying Wang 1105436638acc7c010349a69c3395f1a57c642dc62Ying Wang This program is distributed in the hope that it will be useful, 1205436638acc7c010349a69c3395f1a57c642dc62Ying Wang but WITHOUT ANY WARRANTY; without even the implied warranty of 1305436638acc7c010349a69c3395f1a57c642dc62Ying Wang MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 1405436638acc7c010349a69c3395f1a57c642dc62Ying Wang General Public License for more details. 1505436638acc7c010349a69c3395f1a57c642dc62Ying Wang 1605436638acc7c010349a69c3395f1a57c642dc62Ying Wang You should have received a copy of the GNU General Public 1705436638acc7c010349a69c3395f1a57c642dc62Ying Wang License along with this program; if not, see 1805436638acc7c010349a69c3395f1a57c642dc62Ying Wang <http://www.gnu.org/licenses/>. 1905436638acc7c010349a69c3395f1a57c642dc62Ying Wang */ 2005436638acc7c010349a69c3395f1a57c642dc62Ying Wang 2105436638acc7c010349a69c3395f1a57c642dc62Ying Wang/* Avoid using the symbol _ALLOCA_H here, as Bison assumes _ALLOCA_H 2205436638acc7c010349a69c3395f1a57c642dc62Ying Wang means there is a real alloca function. */ 2305436638acc7c010349a69c3395f1a57c642dc62Ying Wang#ifndef _GL_ALLOCA_H 2405436638acc7c010349a69c3395f1a57c642dc62Ying Wang#define _GL_ALLOCA_H 2505436638acc7c010349a69c3395f1a57c642dc62Ying Wang 2605436638acc7c010349a69c3395f1a57c642dc62Ying Wang/* alloca (N) returns a pointer to N bytes of memory 2705436638acc7c010349a69c3395f1a57c642dc62Ying Wang allocated on the stack, which will last until the function returns. 2805436638acc7c010349a69c3395f1a57c642dc62Ying Wang Use of alloca should be avoided: 2905436638acc7c010349a69c3395f1a57c642dc62Ying Wang - inside arguments of function calls - undefined behaviour, 3005436638acc7c010349a69c3395f1a57c642dc62Ying Wang - in inline functions - the allocation may actually last until the 3105436638acc7c010349a69c3395f1a57c642dc62Ying Wang calling function returns, 3205436638acc7c010349a69c3395f1a57c642dc62Ying Wang - for huge N (say, N >= 65536) - you never know how large (or small) 3305436638acc7c010349a69c3395f1a57c642dc62Ying Wang the stack is, and when the stack cannot fulfill the memory allocation 3405436638acc7c010349a69c3395f1a57c642dc62Ying Wang request, the program just crashes. 3505436638acc7c010349a69c3395f1a57c642dc62Ying Wang */ 3605436638acc7c010349a69c3395f1a57c642dc62Ying Wang 3705436638acc7c010349a69c3395f1a57c642dc62Ying Wang#ifndef alloca 3805436638acc7c010349a69c3395f1a57c642dc62Ying Wang# ifdef __GNUC__ 3905436638acc7c010349a69c3395f1a57c642dc62Ying Wang# define alloca __builtin_alloca 4005436638acc7c010349a69c3395f1a57c642dc62Ying Wang# elif defined _AIX 4105436638acc7c010349a69c3395f1a57c642dc62Ying Wang# define alloca __alloca 4205436638acc7c010349a69c3395f1a57c642dc62Ying Wang# elif defined _MSC_VER 4305436638acc7c010349a69c3395f1a57c642dc62Ying Wang# include <malloc.h> 4405436638acc7c010349a69c3395f1a57c642dc62Ying Wang# define alloca _alloca 4505436638acc7c010349a69c3395f1a57c642dc62Ying Wang# elif defined __DECC && defined __VMS 4605436638acc7c010349a69c3395f1a57c642dc62Ying Wang# define alloca __ALLOCA 4705436638acc7c010349a69c3395f1a57c642dc62Ying Wang# elif defined __TANDEM && defined _TNS_E_TARGET 4805436638acc7c010349a69c3395f1a57c642dc62Ying Wang# ifdef __cplusplus 4905436638acc7c010349a69c3395f1a57c642dc62Ying Wangextern "C" 5005436638acc7c010349a69c3395f1a57c642dc62Ying Wang# endif 5105436638acc7c010349a69c3395f1a57c642dc62Ying Wangvoid *_alloca (unsigned short); 5205436638acc7c010349a69c3395f1a57c642dc62Ying Wang# pragma intrinsic (_alloca) 5305436638acc7c010349a69c3395f1a57c642dc62Ying Wang# define alloca _alloca 5405436638acc7c010349a69c3395f1a57c642dc62Ying Wang# else 5505436638acc7c010349a69c3395f1a57c642dc62Ying Wang# include <stddef.h> 5605436638acc7c010349a69c3395f1a57c642dc62Ying Wang# ifdef __cplusplus 5705436638acc7c010349a69c3395f1a57c642dc62Ying Wangextern "C" 5805436638acc7c010349a69c3395f1a57c642dc62Ying Wang# endif 5905436638acc7c010349a69c3395f1a57c642dc62Ying Wangvoid *alloca (size_t); 6005436638acc7c010349a69c3395f1a57c642dc62Ying Wang# endif 6105436638acc7c010349a69c3395f1a57c642dc62Ying Wang#endif 6205436638acc7c010349a69c3395f1a57c642dc62Ying Wang 6305436638acc7c010349a69c3395f1a57c642dc62Ying Wang#endif /* _GL_ALLOCA_H */ 64