C++ Logo


Advanced search

Re: [wg14/wg21 liaison] Multidimensional subscript operator

From: Ville Voutilainen <ville.voutilainen_at_[hidden]>
Date: Mon, 26 Apr 2021 21:17:05 +0300
On Mon, 26 Apr 2021 at 21:06, Philipp Klaus Krause via Liaison
<liaison_at_[hidden]> wrote:
> Am 26.04.21 um 13:18 schrieb Jens Maurer via Liaison:
> >>
> >> postfix-expression [ expression ]
> >>
> >> to
> >>
> >> postfix-expression [ assignment-expression ]
> >>
> >> Such a change would be better in line with the function operator, for
> >> example, that also only has assignment-expression, here.
> >
> > Sounds good, if WG14 is happy with the backward compatibility break here.
> >
> Making formerly correct code (i.e. using a comma operator in a array
> index) illegal for something that as far as I see, basically is just
> syntactic sugar (a[i,j] vs a[i][j]) doesn't look like something
> WG14-like to me.

But it isn't just sugar. It's the difference between writing one
operation for your type
to provide multi-dimensional indexing, vs. writing an index operation
that returns an object
of a type that has another index operation.

> For comparison:
> We had the proposal (by me, so I might be biased) to change the return
> type of strerror from char * to const char *, which would help avoid
> errors, and more clearly convey what is stated in the descirption of
> strerror anyway. The change got thrown out by WG14 because it could
> result in a warning in badly-written software; that warning was
> considered an unacceptable break of backwards compability by WG14
> (though the strong POSIX veto also contributed to that decision).

That's hideous. Over the last decade or so, it has become increasingly
to write const-correct code in C, even with some POSIX APIs (strcpy,
memcpy, etc.
are const-correct nowadays). It's disappointing that that trend is not
being followed.

(*) I wrote fair amounts of application code in C for Nokia N900. I
was pleasantly surprised
by being able to be const-correct there, and by extension having the
code be ready
for const-correctness in C++, too.

Received on 2021-04-26 13:17:18