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

前端 未结 7 1354
自闭症患者
自闭症患者 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 00:49

    You can convert the warning into an error by using the following compiler options

    -Wreturn-type -Werror=return-type.

    Check out This link

提交回复
热议问题