Why there is no compiler error when return statement is not present?

前端 未结 7 1273
自闭症患者
自闭症患者 2021-01-08 00:19

Unlike Java, in C/C++ following is allowed:

int* foo ()
{
  if(x)
    return p;
// what if control reaches here
}

This oft

7条回答
  •  伪装坚强ぢ
    2021-01-08 01:00

    AFAIR Visual Studio 2008 warns you about "execution path that does not have return value". It is allowed in the meaning of that "C++ won't stop you from shooting you in the foot". So you are to think, not the compiler.

提交回复
热议问题