Информация об изменениях

Сообщение Re[3]: Локальные переменные от 17.08.2025 11:16

Изменено 17.08.2025 11:18 rg45

Re[3]: Локальные переменные
Здравствуйте, kov_serg, Вы писали:

R>>
R>>#include <iostream>

R>>int x;

R>>int main() {
R>>    int y;
R>>    std::cout << x << std::endl;    // OK
R>>    std::cout << y << std::endl;    // warning: 'y' is used uninitialized [-Wuninitialized]
R>>} // а где warning no return value ?
R>>


Ну хорош уже душнить. Отсустсвие return в main трактуется как return 0;

https://timsong-cpp.github.io/cppwp/n4861/basic.start.main#5

6.9.3.1 main function
A return statement ([stmt.return]) in main has the effect of leaving the main function (destroying any objects with automatic storage duration) and calling std​::​exit with the return value as the argument. If control flows off the end of the compound-statement of main, the effect is equivalent to a return with operand 0 (see also [except.handle]).

Re[3]: Локальные переменные
Здравствуйте, kov_serg, Вы писали:

R>>
R>>#include <iostream>

R>>int x;

R>>int main() {
R>>    int y;
R>>    std::cout << x << std::endl;    // OK
R>>    std::cout << y << std::endl;    // warning: 'y' is used uninitialized [-Wuninitialized]
R>>} // а где warning no return value ?
R>>


Ну хорош уже душнить. Отсустсвие return в main трактуется как return 0;

https://timsong-cpp.github.io/cppwp/n4861/basic.start.main#5

6.9.3.1 main function
5 A return statement ([stmt.return]) in main has the effect of leaving the main function (destroying any objects with automatic storage duration) and calling std​::​exit with the return value as the argument. If control flows off the end of the compound-statement of main, the effect is equivalent to a return with operand 0 (see also [except.handle]).