|
Тема |
ето и окончателния отговор [re: void*] |
|
Автор |
void* (психопат) |
|
Публикувано | 22.05.05 03:12 |
|
|
Стандарт:
точка 8.5
5 To zero-initialize storage for an object of type T means:
- if T is a scalar type (3.9), the storage is set to the value of 0 (zero) converted to T;
- if T is a non-union class type, the storage for each nonstatic data member and each base-class subobject is zero-initialized;
- if T is a union type, the storage for its first data member89) is zero-initialized;
- if T is an array type, the storage for each element is zero-initialized;
- if T is a reference type, no initialization is performed.
To default-initialize an object of type T means:
- if T is a non-POD class type (clause 9), the default constructor for T is called (and the initialization is ill-formed if T has no accessible default constructor);
- if T is an array type, each element is default-initialized;
- otherwise, the storage for the object is zero-initialized.
A program that calls for default-initialization of an entity of reference type is ill-formed. If T is a cv-qualified type, the cv-unqualified version of T is used for these definitions of zero-initialization and default-initialization.
6 The memory occupied by any object of static storage duration shall be zero-initialized at program startup before any other initialization takes place. [Note: in some cases, additional initialization is done later. ]
7 An object whose initializer is an empty set of parentheses, i.e., (), shall be default-initialized.
8 [Note: since () is not permitted by the syntax for initializer,
X a();
is not the declaration of an object of class X, but the declaration of a function taking no argument and returning an X. The form () is permitted in certain other initialization contexts (5.3.4, 5.2.3, 12.6.2). ]
9 If no initializer is specified for an object, and the object is of (possibly cv-qualified) non-POD class type (or array thereof), the object shall be default-initialized; if the object is of const-qualified type, the underlying class type shall have a user-declared default constructor. Otherwise, if no initializer is specified for an object, the object and its subobjects, if any, have an indeterminate initial value; if the object or any of its subobjects are of const-qualified type, the program is ill-formed.
та значи:
int i; -> no initializer is specified -> i is garbage.
int j = int(); -> initializer is an empty set of parentheses -> j is zero.
не може да се напише int i(), както може int i(5), защото първото се възприема като декларация на функция, а второто си е initializer.
ако искаш да инициализираш с празни скоби синтактично си длъжен да напишеш T t = T();. няма никакви временни обекти в случая, а в случая на вграден тип и никакви конструктори.
а твърдението "При създаване на временни обекти те гарантирано имат стойност 0", не фигурира в сандарта, така че е грешно. конструирането на временните обекти по нищо не се различава от конструирането на нормалните. главата която ги описва в стандарта е доста кратка и общо взето се занимава с времето на живот при изчисляване на изрази.
ЗАКЛЮЧЕНИЕ:
вградените типове нямат нито конструктори, нито деструктори!!!
друго мнение по въпроса не се приема.
доказателството е от две части и се съдържа в текущия пост, както и в
казах! 
unsigned
|
| |
я пробвайте да компилирате това:
| zaphod
| 20.05.05 12:04 |
Я пак, че не разбрах нещо
| Colombino
| 20.05.05 13:11 |
Re: Я пак, че не разбрах нещо
| Pekoнcтpykтop
| 20.05.05 15:42 |
Не точно
| Colombino
| 20.05.05 16:01 |
Re: Не точно
| Dorian_Gray
| 20.05.05 16:49 |
Именно, де
| Colombino
| 20.05.05 17:00 |
"членове с деструктори"-ебааа!!!
| focusnik
| 20.05.05 17:27 |
Re: Я пак, че не разбрах нещо
| void*
| 20.05.05 17:15 |
Другари!
| BjarneStroustrup®
| 21.05.05 10:07 |
Re: Другари!
| Colombino
| 21.05.05 12:26 |
Re: Другари!
| BjarneStroustrup®
| 21.05.05 12:48 |
Re: Другари!
| Colombino
| 21.05.05 13:15 |
Re: Другари!
| void*
| 22.05.05 02:05 |
Тва на мен ли го казваш?!?
| Colombino
| 22.05.05 14:39 |
Re: Тва на мен ли го казваш?!?
| void*
| 22.05.05 20:07 |
Re: Тва на мен ли го казваш?!?
| BjarneStroustrup®
| 25.05.05 12:32 |
Не вярвам
| Colombino
| 25.05.05 15:45 |
Re: Не вярвам
| BjarneStroustrup®
| 25.05.05 16:35 |
Re: Тва на мен ли го казваш?!?
| void*
| 25.05.05 16:24 |
Re: Тва на мен ли го казваш?!?
| BjarneStroustrup®
| 25.05.05 16:37 |
Re: Другари!
| xyz
| 21.05.05 16:46 |
Re: Другари!
| Colombino
| 21.05.05 20:12 |
Re: Другари!
| zaphod
| 21.05.05 20:40 |
Re: Другари!
| Colombino
| 21.05.05 21:00 |
Re: Другари!
| xyz
| 21.05.05 21:39 |
Re: Другари!
| zaphod
| 21.05.05 23:30 |
Re: Другари!
| xyz
| 22.05.05 01:33 |
Re: Другари!
| zaphod
| 22.05.05 09:02 |
Re: Другари!
| xyz
| 22.05.05 23:20 |
Бъди джигит!
| Colombino
| 22.05.05 23:40 |
Re: Бъди джигит!
| xyz
| 23.05.05 13:14 |
бе това на къв компилатор
| zaphod
| 23.05.05 14:35 |
Re: бе това на къв компилатор
| Colombino
| 23.05.05 14:55 |
оправих го
| zaphod
| 23.05.05 15:03 |
я като си зачекал темата
| zaphod
| 23.05.05 13:37 |
Баси извратения синтаксис!
| Colombino
| 23.05.05 16:20 |
Re: Баси извратения синтаксис!
| zaphod
| 23.05.05 17:49 |
Re: я като си зачекал темата
| void*
| 23.05.05 20:32 |
Re: я като си зачекал темата
| zaphod
| 23.05.05 21:48 |
IDispatch
| ~!@$%amp;^*()_+
| 23.05.05 22:54 |
Re: IDispatch
| zaphod
| 24.05.05 08:33 |
Re: IDispatch
| ~!@$%amp;^*()_+
| 24.05.05 10:02 |
Re: я като си зачекал темата
| void*
| 24.05.05 03:27 |
Re: я като си зачекал темата
| zaphod
| 24.05.05 08:22 |
Re: я като си зачекал темата
| void*
| 24.05.05 14:06 |
тоя метод за викане на конструктор
| zaphod
| 23.05.05 14:26 |
Не бачка?!?
| Colombino
| 23.05.05 14:33 |
Re: Не бачка?!?
| zaphod
| 23.05.05 14:53 |
ами очаквах
| zaphod
| 20.05.05 16:18 |
Я пак помисли
| Colombino
| 20.05.05 16:48 |
Re: ами очаквах
| void*
| 20.05.05 17:19 |
Re: ами очаквах
| Colombino
| 20.05.05 17:25 |
Re: ами очаквах
| void*
| 20.05.05 18:14 |
Re: ами очаквах
| Colombino
| 20.05.05 18:23 |
Re: ами очаквах
| void*
| 20.05.05 18:29 |
Ми не знам
| Colombino
| 20.05.05 18:37 |
Re: Ми не знам
| focusnik
| 20.05.05 18:43 |
Re: Ми не знам
| void*
| 20.05.05 19:11 |
Не съм съгласен, мистерията остава
| Colombino
| 20.05.05 20:01 |
Re: Не съм съгласен, мистерията остава
| void*
| 20.05.05 20:28 |
ето и окончателния отговор
| void*
| 22.05.05 03:12 |
Re: ето и окончателния отговор
| явepтъ
| 24.05.05 02:31 |
Re: Не съм съгласен, мистерията остава
| zaphod
| 20.05.05 22:35 |
Re: Не съм съгласен, мистерията остава
| void*
| 21.05.05 00:56 |
ц++ има адски много кусури
| ~!@$%amp;^*()_+
| 21.05.05 02:04 |
Re: ц++ има адски много кусури
| void*
| 21.05.05 12:01 |
Re: Не съм съгласен, мистерията остава
| zaphod
| 21.05.05 07:56 |
Re: Не съм съгласен, мистерията остава
| BjarneStroustrup®
| 21.05.05 11:14 |
Подкрепям
| Colombino
| 21.05.05 12:32 |
Re: Подкрепям
| BjarneStroustrup®
| 21.05.05 12:50 |
Re: я пробвайте да компилирате това:
| Чвopko
| 20.05.05 13:38 |
Re: я пробвайте да компилирате това:
| Пeтpocян
| 20.05.05 13:40 |
|
|
|
|