Namespaces
Variants
Actions

Talk:cpp/language/zero initialization

From cppreference.com

Contents

[edit] c99 zero init

@ User:Cubbi T t{}; and T t = {0}; are different see [1] Since C99 is fully supported in C++11 we should add this. Do you agree? Yanpas (talk) 07:47, 17 August 2016 (PDT)

They are different, but irrelevant to this page. T t{} is a direct-list-init which invokes value init because the list is empty, T t = {0} is a copy-list-init that, for an aggregate T, invokes copy init of its first element and value init of the remaining elements. C99 is not supported by C++11, and has nothing to do with this anyway (if you're interested in C, see array init and struct init). --Cubbi (talk) 09:05, 17 August 2016 (PDT)

[edit] Syntax 1: static T object;

Does that apply to static the storage qualifier or can it be a static class member? From the mention of thread-local it clearly applies for the storage-qualifier form.

Please clarify this by noting explicitly "static storage duration" - If this were a lesser site I'd do it, however given the importance of this resource and the careful wording required, I dare not.

Thanks

Alec (talk) 04:45, 4 April 2018 (PDT)
the page already says about that line "every named variable with static or thread-local storage duration that is not subject to constant initialization", with a link to the storage duration page - what's ambiguous about it? Note that it certainly can be a static class member. -Cubbi (talk) 07:38, 4 April 2018 (PDT)

[edit] syntax 2

I am unable to understand how the explanation of syntax 2 relates to the syntax presented.--Itaj (talk) 01:58, 20 September 2018 (PDT)

those syntaxes are some of the examples where value initialization may take place. Not an exhaustive list, just examples. --Cubbi (talk) 04:59, 20 September 2018 (PDT)

[edit] Only char arrays? or also wchar_t, char16, char32 arrays?

AFAIK the rule for char arrays ("strings") also applies to wchar_t, char16 and char32 arrays, or not? It should be mentioned here, I think. --Roker (talk) 03:28, 26 November 2018 (PST)

sure, generalized to all char types. --Cubbi (talk) 06:48, 26 November 2018 (PST)

[edit] Syntax section confusing

  • page filename: "zero_initialization"
  • page title: "Zero-initialization"
  • page tagline: "Sets the initial value of an object to zero"
  • first heading: "Syntax"
  • first sentence under first heading: "Note that this is not the syntax for zero-initialization, which does not have a dedicated syntax in the language."

(reader left confused - thought I was here for zero initialization? --Dksmiffs (talk) 10:36, 30 October 2022 (PDT))

This is indeed the zero initialisation page, and there is indeed no dedicated syntax for zero init in the language. It sounds like you didn't try reading beyond the first sentence, which may be the cause of your confusion? --Ybab321 (talk) 13:05, 30 October 2022 (PDT)