1

Topic: Question about std:: list uniform initialization

Greetings! #include <list> class SomeClass {public: SomeClass (int);}; std:: list <SomeClass> some_list {SomeClass (1), SomeClass (2), SomeClass (3), SomeClass (4), SomeClass (5)}; int main () {return 0;} std:: list for each new object selects new storage (with the help operator new) and places there this object (and adds references to the previous and following elements). But how it works in this case - after all program performance, and the list some_list yet did not begin is already created?

2

Re: Question about std:: list uniform initialization

Hello, Maxim Rogozhin, you wrote: > std:: list for each new object selects new storage (with the help operator new) and places there this object (and adds references to the previous and following elements). But how it works in this case - after all program performance, and the list some_list yet did not begin is already created? Generally program performance already began, the main flow of performance was not launched only. Before its start there is an initialization, here in the course of initialization and there are global objects. : once on interviews the different companies plaid about it is "how to fulfill any code prior to the beginning main?". Here so, through the designer of global object.

3

Re: Question about std:: list uniform initialization

Hello, AeroSun, you wrote: AS> Generally program performance already began, the main flow of performance was not launched only. Before its start there is an initialization, here in the course of initialization and there are global objects. AS> : once on interviews the different companies plaid about it is "how to fulfill any code prior to the beginning main?". Here so, through the designer of global object. Thanks! I.e. it differs nothing from such code? #include <list> class SomeClass {public: SomeClass (int);}; std:: list <SomeClass> some_list; int main () {some_list.push_back (SomeClass (1)); some_list.push_back (SomeClass (2)); some_list.push_back (SomeClass (3)); some_list.push_back (SomeClass (4)); some_list.push_back (SomeClass (5)); return 0;} One more question about uniform initialization - the object some_list will be created in static storage, and elements of it some_list where will be created?

4

Re: Question about std:: list uniform initialization

Hello, Maxim Rogozhin, you wrote: > Thanks! I.e. it differs nothing from such code? > >#include <list> > class SomeClass {> public: > SomeClass (int); >}; > std:: list <SomeClass> some_list; > int main () {> some_list.push_back (SomeClass (1)); > some_list.push_back (SomeClass (2)); > some_list.push_back (SomeClass (3)); > some_list.push_back (SomeClass (4)); > some_list.push_back (SomeClass (5)); > return 0; >} > Not absolutely, in the first example creation goes through initializer_list. But as a whole truly is there will be absolutely normal object, the only thing that access to some_list will be from everywhere. > One more question about uniform initialization - the object some_list will be created in static storage, and elements of it some_list where will be created? At creation of objects designers will be caused. In the designer list allocates the elements through new - accordingly all of them will be in a dynamic storage. And to what such question? In a context of global objects static storage only logically differs from dynamic, it should not excite the developer as there the compiler displays global objects in storage.

5

Re: Question about std:: list uniform initialization

> Thanks! I.e. it differs nothing from such code? Differs, it is so-called dynamic initialization. It is fulfilled to a call main. Matters in a context of global objects. > One more question about uniform initialization - the object some_list will be created in static storage, and elements of it some_list where will be created? You in vain mix uniform initialization and dynamic initialization. Because of it at you arises . Uniform initialization it is simple syntax of a call of the designer. List elements form according to used , in this case in a dynamic storage.

6

Re: Question about std:: list uniform initialization

Hello, AeroSun, you wrote: AS> At creation of objects designers will be caused. In the designer list allocates the elements through new - accordingly all of them will be in a dynamic storage. AS> and to what such question? In a context of global objects static storage only logically differs from dynamic, it should not excite the developer as there the compiler displays global objects in storage. Here is how time that such static storage to me was to be specified. I.e. it is the same dynamic storage?

7

Re: Question about std:: list uniform initialization

Hello, Vamp, you wrote: >> Thanks! I.e. it differs nothing from such code? V> Differs, it is so-called dynamic initialization. It is fulfilled to a call main. Matters in a context of global objects. And here it is dynamic or static initialization? #include <list> std:: list <int> some_list {1, 2, 3, 4, 5}; int main () {return 0;}

8

Re: Question about std:: list uniform initialization

Hello, Maxim Rogozhin, you wrote: > Hello, Vamp, you wrote: > And here it is dynamic or static initialization? Dynamic. More in detail here: https://en.cppreference.com/w/cpp/langu … ialization

9

Re: Question about std:: list uniform initialization

Hello, Maxim Rogozhin, you wrote: > Here is how time that such static storage to me was to be specified. I.e. it is the same dynamic storage? Give from the beginning. When process to it well certain amount of addresses of operative storage,  cells of storage with an index I in a range [an is launched, b] to which he can address. Values an and b depend on digit capacity and OS. At process start there is an initialization in which course various things, including selection of storage for a stack (from address process above are fulfilled). Further somewhere it is necessary to allocate the objects which size is known before start. And this all global and static objects. Them is unnecessary to create and track lifetime is all solves for the developer the compiler. Here from the above described address space the area where all these objects are added is selected. Further there was a classification question (in other words how to refer to this area in the documentation). It called "static storage". Even in the course of performance of the program to the programmer the unknown at the moment of compilation an amount of any objects can be demanded. Well that is, their amount can dynamic change. Under these objects the programmer himself selects storage from address  above. And itself releases - the compiler to it in it not the assistant. Further there was a classification question (in other words how to refer to this area in the documentation). It called "dynamic storage". As a rule with static they are nearby. For example, we admit at us address space [0, 100]. That static storage is can be [10, 20], and dynamic - [25, 90]. Therefore the answer to a question above "static is a same dynamic storage?" Depends on the point of view. From the high-level point of view - is not present, these are different types of storage. With low-level - same,  purely speculative (logical).

10

Re: Question about std:: list uniform initialization

Hello, AeroSun, you wrote: AS> Therefore the answer to a question above "static is a same dynamic storage?" Depends on the point of view. From the high-level point of view - is not present, these are different types of storage. With low-level - same,  purely speculative (logical). Thanks big for the detailed answer!