Namespaces
Variants
Views
Actions

Talk:cpp/language/constant initialization

From cppreference.com

Is there a reason why the "const" specifier is missing in the syntax specification on this page? I would expect that within an article about "constant intialization" that would be the case. B166ER (talk) 14:39, 1 January 2018 (PST)

The whole static initialisation section is describing the order of initialisation. Objects are either zero-initialised and then dynamically initialised, or they are constant-initialised; whether the object is declared const isn't considered, just the initialiser itself. As such, you can have non-const variables that are constant-initialised (static int a = 1; as well as const variables that are dynamically initialised (const static unsigned b = std::random_device{}();)). --Ybab321 (talk) 02:42, 2 January 2018 (PST)

Many thanks for the detailed answer! - Sorry for so long delay as I forgot to place this page on my watch list. B166ER (talk) 20:40, 4 January 2018 (PST)

[edit] static in Syntax section is confusing

static here denotes storage duration, not the static keyword. Declaration with static storage duration may or may not be qualified with static. It is better to replace keyword-like static with e.g. static. --Kalaider (talk) 11:43, 18 April 2020 (PDT)

I think the "Syntax" section should be dropped entirely. It's kinda non-trivial and non-conceptual to try to express such semantic notions as "static", "thread-local" and "constexpr" through syntax. In other words, constant initialization is not about syntax, it's about semantics. (Also, currently only copy-initialization is shown, but that is not necessarily the case with constant initialization.) — Radix (talk) 14:49, 2 May 2020 (PDT)
you're right in that "Syntax" in many of the initialization pages is not actually syntax, but rather examples where such initialization may pop up. (just saw another case of someone getting confused by that) Not necessary and not sufficient. Nevertheless, I think it's very useful in cpp/language/copy_initialization, and indeed not so useful here. Perhaps we could restructure them all to open up as bullet points (that already exist, but follow "Syntax") with former 'syntax' entries as micro-examples after each bullet point. --Cubbi (talk) 07:06, 4 May 2020 (PDT)