C++ Logo


Advanced search

Re: Pointers to VLAs as in C99 - (was: Arrays (VLAs) as function parameters (as in C99))

From: Jens Maurer <Jens.Maurer_at_[hidden]>
Date: Sun, 7 Nov 2021 22:29:27 +0100
On 07/11/2021 21.53, Alejandro Colomar (man-pages) wrote:
> Hi Jens,
> On 11/7/21 10:15, Jens Maurer wrote:
>> On 06/11/2021 22.31, Alejandro Colomar (man-pages) via Std-Proposals wrote:
>>> However, VLA syntax for function parameters does not suffer from those
>>> issues: it is just syntactic sugar for pointer parameters.
>> I'm not sure about that. My understanding is that sizeof(param) will
>> yield a runtime value in the body of the called function if "param" is
>> a VLA.
> Hmm, I thought I could hold the other proposal that I had in mind for
> just after this one, but maybe it's the other way around.
> Regarding what you said, the answer is "it depends". It depends if
> we're talking about single-dimension arrays or multi-dimensional arrays.
> There are 2 things going on there:
> - VLA syntax for pointer parameters
> - pointers to VLA
> In C, in the case of a single-dimension array in a function parameter,
> such as
> int foo(int n, int arr[n]);
> it is purely syntactic sugar, as `sizeof(arr)` == `sizeof(int*)` and
> *not* `sizeof(int) * n`.

Good point; seems I was confused.

In general, C99 offers a package of VLAs and variably-modified types
(the "subarrays" you were talking about), and any C++ proposal to
take some or all of that should clearly discuss the delineation of
the choice.

Also, it's not at all clear to me what level of support you'd get
for any proposal in that space. (My proposal for stack-allocated
VLAs was rejected a decade ago or so.)


Received on 2021-11-07 15:29:33