Why does flowing off the end of a non-void function without returning a value not produce a compiler error?

后端 未结 9 2585
粉色の甜心
粉色の甜心 2020-11-21 07:37

Ever since I realized many years ago, that this doesn\'t produce an error by default (in GCC at least), I\'ve always wondered why?

I understand that you can issue co

9条回答
  •  耶瑟儿~
    2020-11-21 07:59

    Under what circumstances doesn't it produce an error? If it declares a return type and doesn't return something, it sounds like an error to me.

    The one exception I can think of is the main() function, which doesn't need a return statement at all (at least in C++; I don't have either of the C standards handy). If there is no return, it will act as if return 0; is the last statement.

提交回复
热议问题