4

Is cppreference.com an official page in any way that one can rely on in terms of the documentation presented there? Or should I simply read the language docs in case I need 100% certainty?

Look at this article. First, several methods of variable initialization have been listed:

Depending on context, the initializer may invoke one of the following:

  • Value initialization
  • Direct initialization
  • Copy initialization
  • List initialization
  • Aggregate initialization
  • Reference initialization

If no initializer is provided, the rules of default initialization apply.

The next part explains two phases of initialization for non-local variables: static and dynamic. Zero initialization happens in the static phase. It doesn't say a word when default initialization takes place though.

When you go to the description of default initialization, there's an example saying:

int n; // static non-class, a two-phase initialization is done:
       // 1) zero initialization initializes n to zero
       // 2) default initialization does nothing, leaving n being zero

Based on this I'd assume default initialization happens some time after zero-initialization (zero init is in the static initialization phase). But this is the only place where actually somebody mentioned when default init takes place relative to other initializations.

Is the cppreference just incomplete, or the information is there and I can't find it?

2
  • What about the section "Explanation" near the top of the page, which begins "Default initialization is performed in three situations:" and then mentions three situations? Commented Mar 1, 2016 at 11:19
  • @molbdnilo it doesn't say when it happens relative to other initializations. Commented Mar 1, 2016 at 13:38

2 Answers 2

3

cppreference is not "official"; it is a wiki. Anyone can edit. It is generally considered to be of fairly high quality, but you should always treat the standard and nothing but the standard as your canonical, authoritative source for information.

As for initialisation, your interpretation is correct: zero-initialisation happens first, then whatever other kind of initialisation is required (be it default initialisation or something else).

This is the only interpretation I can see for the quoted text so I don't see what part of the article is "incomplete".

Sign up to request clarification or add additional context in comments.

6 Comments

It's incomplete because it seemed like the information that default init happens after zero init was given only in the example, and examples generally shouldn't add new information, rather just be illustrative examples.
@user5539357: "The next part explains two phases of initialization for non-local variables: static and dynamic. Zero initialization happens in the static phase." So there's only one phase left for default-initialisation to happen in.
If the quoted example wasn't there in the text, would you know that too? Of course I understand what the example says, my point is that it introduced some completely new information (relative order of default and zero initialization) and generally examples shouldn't do that.
@user5539357: What? Are you complaining that the example was useful and informative? Quit trolling.
Lol no, I was asking if this order was true only in this particular case or in the general case. Remember, it's an example...
|
2

Is cppreference.com an official page in any way

No, not at all.

that one can rely on in terms of the documentation presented there?

It is the best free online C++ documentation I am aware of, and it has good reputation on Stackoverflow.

Or should I simply read the language docs in case I need 100% certainty?

The C++ ISO standard is the one and only official source, so only that can give you 100% certainty. The standard document is not free, but drafts are free and give you, say, 99.99% certainty.

Of course, "100% certainty" may be misleading anyway. Standards are written by human beings and are never free of errors or contradictions, especially when you are dealing with a language as complex as C++. If they were, then there would not be any official issues. There is even a relatively recent official defect report for zero-initialisation.

And you also have to keep in mind that "the C++ ISO standard" could mean "one of the C++ ISO standards which have been published so far" (1998, 2003, 2011, 2014), "the current C++ ISO standard" (2014) or perhaps even the upcoming one (2017).

So maybe the sentence above should be rephrased into: A C++ ISO standard is the one and only official source.

But this is the only place where actually somebody mentioned when default init takes place relative to other initializations.

That's not true. For example, http://en.cppreference.com/w/cpp/language/zero_initialization says:

As described in non-local initialization, static and thread-local variables that aren't constant-initialized (since C++14) are zero-initialized before any other initialization takes place.

There are probably other such explanations throughout the site. But even if your quoted part was the only place in which it is mentioned explicitly, why should that make the explanation incomplete?

1 Comment

Yeah, that was the part I didn't notice: As described in non-local initialization, static and thread-local variables that aren't constant-initialized (since C++14) are zero-initialized before any other initialization takes place.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.