Сообщение Re[3]: Локальные переменные от 17.08.2025 11:16
Изменено 17.08.2025 11:40 rg45
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]).
А также:
https://timsong-cpp.github.io/cppwp/n4861/stmt.return#2
8.7.3 The return statement
2 . . . Otherwise, flowing off the end of a function other than main or a coroutine ([dcl.fct.def.coroutine]) results in undefined behavior.
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]).
А также:
https://timsong-cpp.github.io/cppwp/n4861/stmt.return#2
8.7.3 The return statement
2 . . . Otherwise, flowing off the end of a function other than main or a coroutine ([dcl.fct.def.coroutine]) results in undefined behavior.