This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: alloca (0) in include/libiberty.h
- From: Andrew Haley <aph at redhat dot com>
- To: Martin Liška <mliska at suse dot cz>, GCC Development <gcc at gcc dot gnu dot org>
- Date: Mon, 10 Jun 2019 12:54:36 +0100
- Subject: Re: alloca (0) in include/libiberty.h
- References: <85b35da1-160d-0953-f375-50797a10d58f@suse.cz>
On 6/10/19 8:24 AM, Martin Liška wrote:
> I've just noticed that we have couple of alloca (0) in libiberty:
>
> #ifndef REGEX_MALLOC
> # ifdef C_ALLOCA
> alloca (0);
> # endif
> #endif
>
> If I'm correct the value 0 has a special meaning that tells a C library
> to clean up all previous alloca allocations.
>
> man alloca does not document the behavior
I'm sure it doesn't. This alloca(0) behaviour is a libiberty-internal
thing.
> Question is how legacy is alloca call from a standard library?
alloca(3) is implemented by GCC as a builtin. It's fast, simple, and
widely used. These days you might use variable-length arrays instead,
which are at least portable.
Is there some problem that you want to solve?
--
Andrew Haley
Java Platform Lead Engineer
Red Hat UK Ltd. <https://www.redhat.com>
https://keybase.io/andrewhaley
EAC8 43EB D3EF DB98 CC77 2FAD A5CD 6035 332F A671