5

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.

Shafik Yaghmour
  • 154,301
  • 39
  • 440
  • 740
Brian Bi
  • 111,498
  • 10
  • 176
  • 312
  • The term appears to be first proposed in [N1191](http://www.open-std.org/jtc1/sc22/wg21/docs/papers/1999/n1191.pdf). – T.C. Sep 03 '14 at 03:17
  • 5
    Perhaps it was the fact that it actually *does* always give some sensible value. Default initialization often doesn't. – chris Sep 03 '14 at 03:39

1 Answers1

7

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.

Shafik Yaghmour
  • 154,301
  • 39
  • 440
  • 740
  • OT, but this change introduced an annoying problem; for a POD struct `T foo = T();` and similar such statements was only guaranteed to "work" in C++03, so in portable code you couldn't do it without risking that it'd be run on a C++98 compiler and silently cause dreadful UB. – M.M Sep 03 '14 at 06:02
  • @MattMcNabb that is unfortunate, is there a defect report for that? – Shafik Yaghmour Sep 03 '14 at 17:39
  • Not that I'm aware of, it was just a new thing added in TC1 – M.M Sep 03 '14 at 20:31