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

后端 未结 9 2379
粉色の甜心
粉色の甜心 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 08:23

    I believe this is because of legacy code (C never required return statement so did C++). There is probably huge code base relying on that "feature". But at least there is -Werror=return-type flag on many compilers (including gcc and clang).

提交回复
热议问题