Re[3]: Локальные переменные
От: rg45 СССР  
Дата: 17.08.25 11:16
Оценка: +1
Здравствуйте, 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]).


А также:

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.

--
Справедливость выше закона. А человечность выше справедливости.
Отредактировано 17.08.2025 11:40 rg45 . Предыдущая версия . Еще …
Отредактировано 17.08.2025 11:22 rg45 . Предыдущая версия .
Отредактировано 17.08.2025 11:21 rg45 . Предыдущая версия .
Отредактировано 17.08.2025 11:18 rg45 . Предыдущая версия .
 
Подождите ...
Wait...
Пока на собственное сообщение не было ответов, его можно удалить.