Public Comment Number PC-UK0173 ISO/IEC CD 9899 (SC22N2620) Public Comment =========================================== Date: 1998-03-26 Author: N.M Maclaren Author Affiliation: Self Postal Address: University of Cambridge, Computer Laboratory, New Museums Site, Pembroke Street, Cambridge CB3 3QG, United Kingdom E-mail Address: Telephone Number: +44 1223 334761 Fax Number: +44 1223 334679 Number of individual comments: 1 Comment 1. Category: Feature that should be included Committee Draft subsection: 7.14.3 Title: The alloca 'function' Detailed description: The alloca 'function' is fairly common, but was quite rightly left out of C89 on the grounds of implementation difficulty. However, the introduction of VLAs provides precisely the right mechanism to implement alloca, and this would help with porting some programs that rely on it. There are a few that need it so badly that they cannot be converted to use malloc. Furthermore, many users would like a way of allocating space on the stack and being able to trap failure in a reliable and moderately portable fashion. One of the main arguments against VLAs is that they will reduce program robustness - I don't agree, but the argument is being made. For obvious reasons, alloca cannot be required to use the same space pool as VLAs, but it is expected that most implementations will. The specification here is intended to encourage implementors to return NULL from alloca if space is not available, without making it impossible to implement if detecting that state is infeasible. Note that it is effectively always possible to raise a signal by probing the space after allocation and before return, except on systems where the 'stack' overflows into another data area and there is no global stack limit to check against. However, I have not seen a system that broken in many decades. Even on such a system, the following specification is implementable by always returning NULL. 7.14.3.5 The alloca macro Synopsis [#1] #include void *alloca(size_t size); Description [#2] The alloca macro allocates space for an object with automatic storage duration [6.1.2.4] whose size is specified by size and whose value is indeterminate and returns the address of that object. [#3] It is unspecified whether alloca is a macro or an identifier declared with external linkage. If a macro definition is suppressed in order to access an actual function, or a program defines an external identifier with the name alloca, the behavior is undefined. Returns [#4] The alloca macro returns a pointer to the allocated space if successful. An attempt to obtain more space than is available will either return a null pointer or raise one of an implementation-defined set of signals. Recommended Practice An implementation should attempt to return a NULL pointer as a failure indication if possible. If it is impossible even to raise defined signals reliably, the alloca macro should always return a null pointer.