C++ Logo

liaison

Advanced search

Re: [wg14/wg21 liaison] Multidimensional subscript operator

From: will wray <wjwray_at_[hidden]>
Date: Sun, 25 Apr 2021 14:36:01 -0400
Glad you bring this up.

"generic interoperability with C-style pointer-to-pointer arrays c"


I had a similar reaction on reading that section;
firstly confusion - what exactly does it mean,
then unease - do they know of the approach you show.

Maybe we will never know - this sentence is now gone.
There was an R4 (which still had this section), and now an R5
in which this whole section is redacted.



On Sun, Apr 25, 2021 at 3:27 AM Uecker, Martin via Liaison <
liaison_at_[hidden]> wrote:

>
>
> Just a small comment on P2128R3. There is says
>
> "generic interoperability with C-style pointer-to-pointer
> arrays c"
>
> I assume this refers to code like this to creat
> something which looks like a multi-dimensional array:
>
> double **x = xmalloc(N * sizeof(double*));
>
> for (int i = 0; i < N; i++) {
>
> x[i] = xmalloc(M * sizeof(double));
>
> for (int j = 0; j < M; j++)
> x[i][j] = 0.;
> }
>
>
> I just want to point out that this is not how we
> would do this in C since at least C99. Instead
> we write:
>
> double (*x)[M] = xmalloc(sizeof(double[N][M]));
>
> x[i][j] = 0.;
>
> or sometimes (to more clearly differentiate
> between pointers and arrays):
>
> double (*xp)[N][M] = xmalloc(sizeof *xp);
>
> (*xp)[i][j] = 1.;
>
>
> With this, you the multi-dimensional array is
> a single object and one also gets run-time bounds
> checking for free if the compiler supports this.
>
> Best,
> Martin
>
>
>
>
>
>
>
>
>
>
>
>
> _______________________________________________
> Liaison mailing list
> Liaison_at_[hidden]
> Subscription: https://lists.isocpp.org/mailman/listinfo.cgi/liaison
> Link to this post: http://lists.isocpp.org/liaison/2021/04/0470.php
>

Received on 2021-04-25 13:36:16