Why is value initialization so named?

Brian Bi

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

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.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Why is creating an array with inline initialization so slow?

From Dev

What is a Reparse Point, and why is it named so?

From Dev

Why does setting an initialization value prevent placing a variable on a GPU in TensorFlow?

From Dev

Value initialization: default initialization or zero initialization?

From Dev

Vector of vectors initialization work won't but a matrix array does, why so?

From Dev

Structuring value initialization

From Dev

Uniform and Value-initialization

From Dev

Structuring value initialization

From Dev

Is value initialization part of the C++98 standard? If not, why was it added in the C++03 standard?

From Dev

Why am I getting warning: (near initialization for ‘ptr’) and segmentation fault at runtime when accsessing value at pointer?

From Dev

Direct Initialization vs. Value Initialization

From Dev

Direct Initialization vs. Value Initialization

From Dev

Why is the destructor in Delphi named?

From Dev

Why are named constructors static

From Dev

Why does un-named object returned by value get destructed before its conversion operator is called?

From Dev

Why is the HID_MAX_USAGES value so low in kernel?

From Dev

Why is the HID_MAX_USAGES value so low in kernel?

From Dev

why is the garbage value for an integer so un-integerly huge

From Dev

Why is array initialization in a static context?

From Dev

Why char initialization difference? C

From Dev

why two ways to variable initialization

From Dev

Why are setter methods not used in initialization?

From Dev

Why does the compiler not optimize this initialization?

From Dev

Why Collection Initialization Throws NullReferenceException

From Dev

Why Collection Initialization Throws NullReferenceException

From Java

Default, value and zero initialization mess

From Dev

Value initialization of POD struct is a constexpr?

From Dev

C++ Struct Value Initialization

From Dev

Primitive Array initialization without value?

Related Related

  1. 1

    Why is creating an array with inline initialization so slow?

  2. 2

    What is a Reparse Point, and why is it named so?

  3. 3

    Why does setting an initialization value prevent placing a variable on a GPU in TensorFlow?

  4. 4

    Value initialization: default initialization or zero initialization?

  5. 5

    Vector of vectors initialization work won't but a matrix array does, why so?

  6. 6

    Structuring value initialization

  7. 7

    Uniform and Value-initialization

  8. 8

    Structuring value initialization

  9. 9

    Is value initialization part of the C++98 standard? If not, why was it added in the C++03 standard?

  10. 10

    Why am I getting warning: (near initialization for ‘ptr’) and segmentation fault at runtime when accsessing value at pointer?

  11. 11

    Direct Initialization vs. Value Initialization

  12. 12

    Direct Initialization vs. Value Initialization

  13. 13

    Why is the destructor in Delphi named?

  14. 14

    Why are named constructors static

  15. 15

    Why does un-named object returned by value get destructed before its conversion operator is called?

  16. 16

    Why is the HID_MAX_USAGES value so low in kernel?

  17. 17

    Why is the HID_MAX_USAGES value so low in kernel?

  18. 18

    why is the garbage value for an integer so un-integerly huge

  19. 19

    Why is array initialization in a static context?

  20. 20

    Why char initialization difference? C

  21. 21

    why two ways to variable initialization

  22. 22

    Why are setter methods not used in initialization?

  23. 23

    Why does the compiler not optimize this initialization?

  24. 24

    Why Collection Initialization Throws NullReferenceException

  25. 25

    Why Collection Initialization Throws NullReferenceException

  26. 26

    Default, value and zero initialization mess

  27. 27

    Value initialization of POD struct is a constexpr?

  28. 28

    C++ Struct Value Initialization

  29. 29

    Primitive Array initialization without value?

HotTag

Archive