C function defined as int but having no return statement in the body still compiles

后端 未结 7 2147
走了就别回头了
走了就别回头了 2020-11-28 13:48

Say you have a C code like this:

#include 

int main(){
    printf("Hello, world!\\n");
    printf("%d\\n", f());    
}

in         


        
7条回答
  •  挽巷
    挽巷 (楼主)
    2020-11-28 14:15

    I compile with -Werror=return-type to prevent this. GCC will give an error if you don't return from a function (unless it's void return).

提交回复
热议问题