Path: csiph.com!eternal-september.org!feeder.eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: Tim Rentsch
Newsgroups: comp.lang.c
Subject: Re: alloca()-support
Date: Sun, 06 Oct 2019 06:16:49 -0700
Organization: A noiseless patient Spider
Lines: 41
Message-ID: <86k19i9fpa.fsf@linuxsc.com>
References:
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Info: reader02.eternal-september.org; posting-host="a0bfc71282e15a9952a47d73886d6801"; logging-data="16009"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18GLvQ/W7zKEZSwhl9vv3CW+zzCQZqIj98="
User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Cancel-Lock: sha1:eZ9lkDLUR1wa41er+xhZtm9NBmg= sha1:5netNdrRwkCeFDN000Jk6dFYYjg=
Xref: csiph.com comp.lang.c:146633
Keith Thompson writes:
> Soviet_Mario writes:
>
>> On 30/09/2019 18:58, Bonita Montero wrote:
>>
>>>>>> Since when (if at any time) was variable size automatic
>>>>>> array supported ?
>>>>>
>>>>> Since C99.
>>>>
>>>> for curiosity, this feature has one or more of the
>>>> limitations I feared ... or even none of them ?
>>>
>>> Yes, you could run out of stack-space, maybe hitting a
>>> guard-page
>>> in the best case so that you wouldn't corrupt any other data.
>>
>> uhm, I didn't mean THAT kind of risk (unavoidable), but the
>> possible difficulties in defining variables beyond the point
>> of declaration of the variable-size array.
>>
>> I can't figure out how the compiler would reference them in
>> standard efficient ways (use of registers).
>>
>> Anyway, the difference with alloca () would be in a safer
>> management of possible collisions and running out of stack
>> space ? (compared with the plain declarations) ?
>
> No. Neither VLAs nor alloca() provide any protection against
> running out of space. Both have undefined behavior if there isn't
> enough memory for the allocation.
The function alloca() is extra-linguistic, and is not -- nor can
it be -- written in C. From that point of view it has undefined
behavior no matter what argument value is given.
Declaring a VLA that needs more memory than is available is not
undefined behavior, any more than declaring a fixed-size array of
the same size is undefined behavior. Both can blow up at
runtime, but neither one is undefined behavior.