C++ Logo


Advanced search

Re: [SG20] "constinit" seems to be very confusing

From: Balog Pal <pasa_at_[hidden]>
Date: Sun, 22 Nov 2020 16:47:26 +0100
On 11/22/2020 4:07 PM, Nicolai Josuttis via SG20 wrote:
> Starting to learn and document C++20, I just realized that
> the keyword "constinit" seems very confusing.
> Every naive programmer would assume it means "init a const",
> but it seems the const is simply wrong; it is the opposite.
> Or as Jonathan Müller wrote in a talk:
> constinit = constexpr - const
> Now I wonder how to teach that.
> Could somebody elaborate please why we have chosen this name
> and what is the best way to make this name plausible to ordinary
> programmers?

IMHO constexpr is the real troublemaker here. Also the hacked const that
implicitly drags internal linkage. Compared to those costinit is not
even worth mentioning. If you teach that you probably need a table
anyway with all the properties of every incantation, then it will just
disappear in the crowd.

Received on 2020-11-22 09:47:33