On Tue, 13 Mar 2007, Andrey Chernov wrote: > Copy the segment below to the file a.c > ---------------------- cut me here --------------------- > #include <stdio.h> > > main() { > printf("%s\n", NULL); > } > ---------------------- cut me here --------------------- > It calls "puts(NULL)" with core dump. > It means "printf("%s\n", NULL)" is overoptimized. > BTW, things like "printf("1%s\n", NULL)" are not overoptimized. > Any ideas? Is it right or needs to be fixed? This happens with gcc-3.4.6 and 4.2 but not with 3.3.3. It also happens if NULL is replaced by a variable containing a null pointer. The case of a literal NULL should probably be an error at compile time (__nonnull() doesn't apply to printf() but the compiler could detect this error when it optimizes to use puts()). This is not wrong, since the null pointer gives undefined behaviour, but it breaks the normal undefined behaviour of printing "(null)". BruceReceived on Tue Mar 13 2007 - 12:05:34 UTC
This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:39:06 UTC