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

前端 未结 7 1264
自闭症患者
自闭症患者 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:52

    Use -Wall flag in gcc.

     warning: control reaches end of non-void function
    

    EDIT: or more specifically -Wreturn-type.

提交回复
热议问题