Path: ...!news.mixmin.net!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Tim Rentsch
Newsgroups: comp.lang.c
Subject: Re: filling area by color atack safety
Date: Wed, 20 Mar 2024 07:52:12 -0700
Organization: A noiseless patient Spider
Lines: 68
Message-ID: <864jd1lzvn.fsf@linuxsc.com>
References: <86h6h3nvyz.fsf@linuxsc.com> <865xxiok09.fsf@linuxsc.com> <20240319131842.00002138@yahoo.com> <86o7b9ms7d.fsf@linuxsc.com> <20240320115416.00001ab5@yahoo.com> <87jzlxi4lq.fsf@bsb.me.uk>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Info: dont-email.me; posting-host="7a780175fd21d30328a8a78d1217a04c";
logging-data="1632892"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+TP07FUG0XcIA/ZP01YrVFxdcw4f+v/kw="
User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Cancel-Lock: sha1:5PAbnrh33goJwjtV7UoGUN4kZxE=
sha1:fr90DgMjILX9G2zidGsdAUZPYBo=
Bytes: 3460
Ben Bacarisse writes:
> Michael S writes:
>
>> On Tue, 19 Mar 2024 21:40:22 -0700
>> Tim Rentsch wrote:
>>
>>> Michael S writes:
>
> ...
>
>>>>> Tim Rentsch writes:
>
> ...
>
>>>>> static _Bool change_it( UI w, UI h, Color [w][h], Point, Color,
>>>>> Color );
>>>>
>>>> Besides, I don't think that use of VLA in library code is a
>>>> good idea. VLA is optional in latest C standards. And
>>>> incompatible with C++.
>>>
>>> The code uses a variably modified type, not a variable length
>>> array.
>>
>> I am not sufficiently versed in C Standard terminology to see a
>> difference.
>
> A VLA is a declared object -- an array with a size that is not a
> compile-time constant. A variably modified type is just a type,
> not an object. Obviously one can use such a type to declare a
> VLA, but when it is the type of a function parameter, there need
> be no declared object with that type. Usually the associated
> function argument will have been dynamically allocated.
Also ordinary local variables can be declared to have a variably
modified type (the type not necessarily having been introduced
separately), often a benefit for code that is dealing with
multi-dimensional arrays.
>> Aren't they both introduced in C99 and made optional in later
>> standards?
>
> I think so but that's a shame since VMTs are very helpful for
> writing array code. They avoid the need to keep calculating the
> index with multiplications.
C11 added a pre-defined preprocessor macro __STDC_NO_VLA__, which
implementations can define to be 1 "intended to indicate that the
implementation does not support variable length arrays or variably
modified types." It's amusing to note that an implementation can
support VLAs and VMTs but still define the macro if they are not
intended to be supported. ;)
> Making both optional was a classic case of throwing the baby out
> with the bath water. Few of the objections raised about VLAs
> apply to VMTs.
Agree 100%.
Someone who wants to take a stand on this issue might to consider
adding the following lines
#if __STDC_NO_VLA__
#error Substandard implementation detected
#endif
at various places around their source code.