optimization/4130: gcc 3.0 -O2 and printf optimization

Richard Henderson rth@redhat.com
Wed Apr 3 10:31:00 GMT 2002


----- Forwarded message from "Kaveh R. Ghazi" <ghazi@caip.rutgers.edu> -----

In addition, the builtin printf optimization (really all stdio
builtins) are not performed if the return value is examined.  This is
specifically to address the particular problem of how these functions
all differently handle return values and errno.  So if you're actually
going to examine errno, you should do it as I've done below.  (Code
rewritten from the example provided in the PR):

 > #include <stdio.h>
 > #include <errno.h>
 > int main(void)
 > {
 >   if (printf ("foo\xC0\n") < 0)
 >     perror("printf");
 >   return 0;
 > }

or something similar.  In this case, the optimization to `puts' is not
done.



More information about the Gcc-bugs mailing list