Search code examples
c++initializationvalue-initialization

Why is value initialization so named?


It's really unclear to me why anyone would name a particular form of initialization "value initialization". It sounds as though it's initializing the object by giving it a value... but that's what initialization does in general, and the name doesn't tell you anything about which value it's going to use for the initialization.


Solution

  • The Boost value_init write-up provide a rather detailed history of value initialization it ended up in the standard from defect report 178: More on value-initialization and it seems like the term originated from defect report 35: Definition of default-initialization. Although none of these documents really provide a proper origin for the term it does provide some good ideas, it says:

    The first Technical Corrigendum for the C++ Standard (TC1), whose draft was released to the public in November 2001, introduced Core Issue 178 (among many other issues, of course).

    That issue introduced the new concept of value-initialization (it also fixed the wording for zero-initialization). Informally, value-initialization is similar to default-initialization with the exception that in some cases non-static data members and base class sub-objects are also value-initialized. The difference is that an object that is value-initialized won't have (or at least is less likely to have) indeterminate values for data members and base class sub-objects; unlike the case of an object default constructed. (see Core Issue 178 for a normative description).

    In order to specify value-initialization of an object we need to use the empty-set initializer: ().

    and value initialization is less likely to leave an object with an indeterminate value versus default-initalization.