Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How Do Zero-Initialization, Static-Initialization, and Value-Initialization Differ?

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.

like image 434
Jonathan Mee Avatar asked Jun 09 '16 16:06

Jonathan Mee


1 Answers

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 value-initialization or static-initialization will apply, and I can't see much value in using up your tag quota to apply zero-initialization as well.

like image 161
ecatmur Avatar answered Sep 27 '22 22:09

ecatmur