"format not a string literal"

Kaveh R. Ghazi ghazi@caip.rutgers.edu
Thu Oct 14 07:50:00 GMT 1999

 > From: Ulrich Drepper <drepper@cygnus.com>
 > The code is just fine and there are several other cases which now
 > fail.  E.g., one frequent case is:
 > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 > #include <stdio.h>
 > void
 > foo (int n)
 > {
 >   printf (n == 1 ? "%d file" : "%d files", n);
 > }
 > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 > (I know this is not really good from i18n perspective, it's still used
 > quite often).  Or getting a string from an array of format strings.
 > This all produces the same warning.  Not every use of printf-like
 > functions is as unsophisticated as the ones you have in your code.

I have more sympathy for your previous example that for these two.  We
should distinguish between impossible (or very hard) to fix situations
and fixable ones like the above.

An easy to fix bad behavior is not a reason to change the warning,
even if lots of people do it.  This is especially true if the warning
points exactly to the place where the problem occurs and the fix is
immediately clear.

Note I submitted patches to fix the cases in gcc which did the above
?: silliness as well as several array format string usages.  The
warning in those cases is entirely legitimate.

I still think we need to address your previous problem though.  (The
one where you pass a stmt-expr as a fprintf format string.)  I haven't
yet thought of a way to address it without shutting off the warning.
Do you have any ideas?

Kaveh R. Ghazi			Engagement Manager / Project Services
ghazi@caip.rutgers.edu		Qwest Internet Solutions

More information about the Gcc-bugs mailing list