News for hackers. Stuff that matters.
Re:There is no 'printf' by Computeiful on Thursday October 21, 2021 @09:24PM (#28952793)
Yeah honestly this blog post just seems to be highlighting a bug in gcc when it is compiling to an older version of C. Not sure why the author chose to frame it as some big point about the printf function.
Re:There is no 'printf' by varajelle on Friday October 22, 2021 @12:12AM (#28953691)
Not a bug in GCC. The program GCC tries to compile is invalid, and the C standard says GCC can do anything it please in that case. So GCC is fine, just fix your program.
Re:There is no 'printf' by roywiggins on Thursday October 21, 2021 @10:24PM (#28953095)
I think that's because the only way to see puts() return value after calling printf is in this weird situation. If you actually assign the return value somewhere and read it, the compiler can't replace it with puts and you'll get the return value you expect. But in this case the compiler is tricked into exposing that it's really calling puts().
Re:There is no 'printf' by ncmncm on Friday October 22, 2021 @05:41PM (#28963104)
When I do it on Linux, with gcc 10.2.1, it always returns 0, regardless of "-ansi", "-O2", or what-have-you. So, the author's experience is either peculiar to some old version of cc he used, or to a quirk of BSD.

The ISO C++ Standard dictates that if main fails to return a result, the program result is zero. And, g++ does this.

[Edit: I'm wrong... with "gcc -ansi -std=c90", with or without optimization, I get the 13! But not 10.]