Date: Thu, 22 Jan 2026 08:45:50 -0800
On Thursday, 22 January 2026 01:26:44 Pacific Standard Time M.P. via Std-
Proposals wrote:
> The `constinit` keyword sounds like exactly what you're looking for.
> It's been available since C++20.
That forces you to write code that must be initialised at compile time (stored
in the .tdata section if not zeroes), but it's not sufficient for the problem.
To "solve" this problem of initialisation, all accesses to the variable must
see the initialisation. And if the variable is used over multiple TUs, then it
needs to be inline.
Given most code is PIC, I don't see much value in accessing the variable
directly. Make it static in one TU and add an accessor function.
Proposals wrote:
> The `constinit` keyword sounds like exactly what you're looking for.
> It's been available since C++20.
That forces you to write code that must be initialised at compile time (stored
in the .tdata section if not zeroes), but it's not sufficient for the problem.
To "solve" this problem of initialisation, all accesses to the variable must
see the initialisation. And if the variable is used over multiple TUs, then it
needs to be inline.
Given most code is PIC, I don't see much value in accessing the variable
directly. Make it static in one TU and add an accessor function.
-- Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org Principal Engineer - Intel Data Center - Platform & Sys. Eng.
Received on 2026-01-22 16:45:59
