Mail Archives: djgpp-workers/2002/05/27/12:37:34
Martin Stromberg wrote:
>
> Consider this program (h.c):
>
> #include <stdio.h>
>
> int main(void)
> {
> char s[10];
>
> printf("");
> sprintf(s, "");
> return 0;
> }
>
... snip gcc 3.1 ...
>
> gcc -Wall h.c -O2 says:
>
> h.c: In function `main':
> h.c:7: warning: zero-length format string
> h.c:8: warning: zero-length format string
>
> Why is a "" format string worthy of a warning?
>
> There are perfectly legitimate uses for emtpy format strings,
> e. g. automatically generated ones.
>
> Can anyone give me a valid good reason why a "" format string
> _should_ generate a warning?
To me a warning is just that. It says "I know just how to handle
this, but it is unusual and did you really mean it?". While, as
you say, auto generated code can include such empty format
strings, I can think of no reason for human generated code to do
so, when it is most likely a typo.
If the compiler has to do error recovery to continue, and possibly
suppress statements as a result, it is an error.
There could well be an argument for a way of suppressing this
particular (and other) warnings, but that does not make it
superfluous. Similarly I want a warning for nested comments, for
just one further example.
Just in case there is any doubt, I approve :-)
--
Chuck F (cbfalconer AT yahoo DOT com) (cbfalconer AT worldnet DOT att DOT net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net> USE worldnet address!
- Raw text -