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

后端 未结 7 2118
走了就别回头了
走了就别回头了 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:19

    14 is exactly the return value of the first printf, also. Probably, the compiler optimized out the call to f() and then we're left with 14 on EAX.

    Try compiling your code with different optimization levels (-O0, -O1, -O2, -O3, -Os) and see if the output changes.

    0 讨论(0)
提交回复
热议问题