C++ Logo

sg20

Advanced search

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

From: Tony V E <tvaneerd_at_[hidden]>
Date: Sun, 22 Nov 2020 18:23:17 -0500
We could have reused static! (again)

int x = static f();

:-)


Sent from my BlackBerry portable Babbage Device
From: Gabriel Dos Reis via SG20
Sent: Sunday, November 22, 2020 3:54 PM
To: ext_at_[hidden]
Reply To: sg20_at_[hidden]
Cc: Gabriel Dos Reis; C++ Education Reflector; Barry Revzin
Subject: Re: [SG20] [isocpp-ext] "constinit" seems to be very confusing

We used to call it "static initialization" - which contrasted with dynamic initialization.

-- Gaby



From: Ext <ext-bounces_at_[hidden]> on behalf of Barry Revzin via Ext <ext_at_[hidden]>
Sent: Sunday, November 22, 2020, 7:16 AM
To: Evolution Working Group mailing list
Cc: Barry Revzin; C++ Education Reflector
Subject: Re: [isocpp-ext] "constinit" seems to be very confusing



On Sun, Nov 22, 2020 at 9:08 AM Nicolai Josuttis via Ext <ext_at_[hidden]> 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?

Thanks
  Nico

The name comes from mandating that we perform constant initialization for this variable.

Barry


Received on 2020-11-22 17:23:22