"format not a string literal"

Tom Tromey tromey@cygnus.com
Thu Oct 14 10:45:00 GMT 1999

>>>>> "Kaveh" == Kaveh R Ghazi <ghazi@caip.rutgers.edu> writes:

>> printf (n == 1 ? "%d file" : "%d files", n);

Kaveh> You're just simply not getting a format check here.  (One could
Kaveh> argue the warning should be rewritten to handle this, but there
Kaveh> are many such cases and this work would never be done.)

I've always loved -Wformat.  However, I'm not enthused about the new
change.  When I write cod like the above (which happens rarely, I'll
admit), I know that -Wformat isn't going to check it.  I don't expect
it to check it.  I only expect -Wformat to check when the format
argument is a literal string.

Adding a new warning for this makes -Wformat less useful for me.  I'd
rather see a -Wformat-full or something to enable the additional
warnings.  That way I can choose not to use it.

>> if (n == 1)
>> printf ("%d file", n);
>> else
>> printf ("%d files", n);

This isn't a practical change to make.  For one thing it leads to code
explosion.  Suppose, as in Ulrich's other example, that you have an
array of format strings.

Kaveh> Also according to Ulrich, calling ?: in a format string is not
Kaveh> good from an intl perspective.  So in general its best to fix
Kaveh> these cases.

No, he meant that his particular example (pluralization) was bad for
i18n.  In general the use of ?: in a format string has nothing to do
with i18n.


More information about the Gcc-patches mailing list