7

Ben Voigt has pointed out here that:

Zero initialization is one of the steps of static initialization. But you're right that you can't blindly substitute the latter (tag), since zero initialization is also performed for value initialization. However, there's no need for (a tag named) zero-initialization in the context of C++, because tags already exist for both static initialization and value initialization, and those are more relevant.

I thought there was a case where it made sense to "Zero-Initialize" rather than "Static-Initializing" or "Value-Initializing" or is "Zero-Initialization" never going to happen in the wild, and I should use more specific terms like: "Static-Initialization" or "Value-Initialization"?

To be fair most of my experience on these topics comes from studying the answers to this question, so I'm sure Ben Voigt is right, I'd just like someone to spell out why.

10
  • It seems that this question is more for meta.SO than SO as it is about tags... Commented Jun 9, 2016 at 17:05
  • @Jarod42 Well the question in my mind is one of concepts. I think I'm missing what Ben Voigt is saying because I don't understand the difference between these initializations. I'm not sure how we can get into that technicality on the meta. Commented Jun 9, 2016 at 17:12
  • @Jarod I don't think so. It is a meta question, as Jonathan is asking not about C++ but about terminology used by the Standard and experts to talk about C++. But SO is still the right site, meta.SO is only for the subset of meta questions which are about the Stack Overflow software and policies and this isn't. Commented Jun 9, 2016 at 17:16
  • 1
    You could argue that Programmers is a better home... But not meta.SO Commented Jun 9, 2016 at 17:18
  • Zero-initialization is a technical part of some other initialization really "asked" by user. The "complexity" is for those initializations. In addition zero-initialization doesn't group those initialization either. Commented Jun 9, 2016 at 17:24

1 Answer 1

4

Zero-initialization can occur on its own; when a character array is initialized using a string literal that is shorter than the array, the remaining characters are zero-initialized. But in all other cases, zero-initialization occurs during value-initialization, or as the static-initialization step of initializing an object with static or thread-local storage duration (this can occur on its own, or preparatory to dynamic initialization).

So unless you're asking about the zero representations for character types (and I can't see there being many questions in that topic) one of the other tags or will apply, and I can't see much value in using up your tag quota to apply as well.

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

7 Comments

Zero-Initialization is just, default-initialization then?
I don't know why we even still have that rule, since the more general " If there are fewer initializer-clauses in the list than there are elements in the aggregate, then each element not explicitly initialized shall be initialized from its default member initializer (9.2) or, if there is no default member initializer, from an empty initializer list (8.5.4)." already guarantees the same behavior, as initialization of character types from an empty initializer list is value initialization is zero initialization.
@JonathanMee: No, it's not default initialization, which can call a user constructor. There are really two different categories. The first is what happens when an object is created from {} and the type's default constructor is trivial a/k/a value-initialization (formally this doesn't happen for character arrays, but I know of no actual difference between what happens there and for all other aggregates with more elements than initializers). This case can't ever arise if the type does have a user-defined default constructor.
@JonathanMee: The other case is a partial mitigation of the "static initialization order fiasco". For automatic storage, the value of an object before its initialization has started is an indeterminate value, and inspecting it leads to undefined behavior (slowly for character types, immediately for all others). But objects of static storage duration can sometimes be inspected prior to initialization, the value is zero not indeterminate, and this applies even if the object type does have a default constructor, because dynamic construction hasn't yet occurred.
"preparatory to static initialization" - you mean preparatory to dynamic initialization. "static initialization" doesn't mean "initialization of an object of static storage duration"; it means something else.
|

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.