EDIT: since C99, reaching the } that terminates the main function returns a value of 0.
'The returned value is undefined' is not true. If the return value is used(in the case of main(), the host environment cares about it), you get undefined behavior and give the compiler and runtime the right to do whatever they want to do including invoking something like rm -rf /. Since gcc uses -std=gnu89 by default, it is not safe to omit return 0; in main(). ISO/IEC 9899:201X Programming languages — C 6.9.1 Function definitions 12 If the } that terminates a function is reached, and the value of the function call is used by the caller, the behavior is undefined. ------------------ Best regards, lh_mouse 2014-07-24 ------------------------------------------------------------- 发件人:Óscar Fuentes <[email protected]> 发送日期:2014-07-24 10:52 收件人:mingw-w64-public 抄送: 主题:Re: [Mingw-w64-public] fork is an inbuilt function? Apart from what lh_mouse says about C++, in C if your function is declared to return an int and there is no return statement the returned value is undefined (not to be confused with undefined behavior, which only happens on this case if you *use* the value returned by that function.) So you can omit the return at the end of `main' on your toy C program unless you plan to use the process' exit value. ------------------------------------------------------------------------------ Want fast and easy access to all the code in your enterprise? Index and search up to 200,000 lines of code with a free copy of Black Duck Code Sight - the same software that powers the world's largest code search on Ohloh, the Black Duck Open Hub! Try it now. http://p.sf.net/sfu/bds _______________________________________________ Mingw-w64-public mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/mingw-w64-public
