C++ Logo

liaison

Advanced search

Re: [wg14/wg21 liaison] Multidimensional subscript operator

From: Uecker, Martin <Martin.Uecker_at_[hidden]>
Date: Tue, 27 Apr 2021 05:47:38 +0000
Am Dienstag, den 27.04.2021, 00:51 +0300 schrieb Ville Voutilainen:
> On Tue, 27 Apr 2021 at 00:30, Uecker, Martin
> <Martin.Uecker_at_[hidden]> wrote:
> > > > Of course, in C++ you could also use a template
> > > > instead of a macro:
> > > >
> > > > c_array<int, 3> x; // same type as int[3]
> > >
> > > Yeah, funny how we already have std::array that looks like that, and
> > > it just solves this problem, more in the next.
> >
> > Except one is compatible with everything else in the
> > world and one is a different one C++ introduced in addition
> > to makes things... simpler?
>
> It does make things simpler. We can relegate legacy arrays to very
> contained portions
> of our code, and use the more regular facilities elsewhere. Sure, we
> need an array
> for the implementation guts for std::vector and std::array, and std::span covers
> the rest. But we don't need to pass or return legacy arrays, or
> otherwise manipulate
> them, pretty much *anywhere*. So whether they're regular or whether
> they fit in with
> the rest becomes irrelevant.

Then we should probably agree that C and C++ will
evolve in different directions and not stop trying
to maintain a common subset anymore.

Because if C++ now starts claiming syntax for new C++
arrays while sidelining C arrays to a legacy feature, then
this obviously can't work.


> > Only if you close your eyes and ignore the types for which this
> > currently does not work (because C++ inherited them from C and
> > still uses C's declarator syntax and which it still needs for
> > compatibility with the rest of the world).
> >
> > Changing the declarator syntax would make it truly work for
> > all types. *That* would be regular.
>
> Well, that's if you can *change* the declarator syntax, instead of adding to it.
> Which takes a loooong time. Perhaps we should instead consider adding a regular
> array type to C and have C++ adopt it, too.

Add a new syntax I mean.

I do not want a new type and all its ABI issues and there is
simply no reason to have new types just to fix syntax issues.


> > > Well, with a reinvented type, the declarator syntax works fine, and we
> > > don't need to invent
> > > new declarator syntaxes. So I'd step very cautiously before agreeing
> > > with that conclusion
> > > of yours about what we should do.
> >
> > In this way C++ created a parallel universe of new types but
> > will probably still not be able to get rif of the C arrays
> > any time soon. And by ignoring them you make them even more
> > the irregular corner case instead of a proper part of the
> > type system. This is then a self-fulfilling prophecy.
>
> Sure, but it works splendidly well. And it probably becomes an
> argument against P1997;
> right now, the legacy arrays are contained in their dusty corners.
> P1997 makes them
> crawl out.


I would also appreciate more professional language
instead of "dusty corner", "crawl out". It would help
to base discussions on technical arguments instead
of appealing to emotions.


> > When I check what applications I personally use,
> > many of them are written in C.
>
> I use some myself, the GNOME ones. I can't fathom why they bother.
> Feel free to add destructors to C and we can talk. :)



Best,
Martin


Received on 2021-04-27 00:47:56