This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: alloca + inline
- From: Geoff Keating <geoffk at geoffk dot org>
- To: dewar at gnat dot com (Robert Dewar)
- Cc: gcc at gcc dot gnu dot org
- Date: 15 Mar 2003 15:37:28 -0800
- Subject: Re: alloca + inline
- References: <20030315214044.72822F2E11@nile.gnat.com>
dewar at gnat dot com (Robert Dewar) writes:
> > In fact, assuming almost anything where a reasonable implementation
> > could change, is not a good idea. Certainly GCC will not apologize
> > for breaking code whose correctness depends on such assumptions.
>
> Surely your comment does not apply to use of the attribute ...
>
> For the interesting alloca case, I would certainly say that the
> attribute must be used. Whether it "works" with the attribute is an
> interesting discussion. There are various possible outcomes of such
> a discussion:
>
> 1. It does not work now, and we don't care
>
> 2. It works now, but by accident, and might stop working in the future
>
> 3. It works now, and you can reasonably expect it to work in the future
> (obviously guarantees can be made in this environment).
Or
4. It works now, and that's a bug. Please submit a patch to make it
stop working...
In this case, the definition of 'alloca' is clear: the storage it
allocates lasts until the end of the function. So, this program
should work (modulo typos):
static int get_int(void)
{
char *s = alloca (1024);
fgets (stdin, s);
return atoi (s);
}
int main(void)
{
int i;
for (i = 0; i < 10000; i++)
printf ("%d\n", get_int());
return 0;
}
but it doesn't if you have less than 10Mb of stack space and get_int
gets inlined.
--
- Geoffrey Keating <geoffk at geoffk dot org>