C function defined as int but having no return sta

2019-01-11 23:09发布

Say you have a C code like this:

#include <stdio.h>

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

int f(){

}

It compiles fine with gcc, and the output (on my system) is:

Hello, world!

14

But.. but.. how is that possible? I thought that C won't let you compile something like that because f() doesn't have a return statement returning an integer. Why is that allowed? Is it a C feature or compiler omission, and where did 14 come from?

标签: c compilation
7条回答
疯言疯语
2楼-- · 2019-01-12 00:09

You probably have the warning level of your compiler set very low. So it is allowed, even if the result is undefined.

查看更多
登录 后发表回答