www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp-workers/2002/05/27/12:37:34

Message-ID: <3CF253C5.EB741556@yahoo.com>
Date: Mon, 27 May 2002 11:41:57 -0400
From: CBFalconer <cbfalconer AT yahoo DOT com>
Organization: Ched Research
X-Mailer: Mozilla 4.75 [en] (Win98; U)
X-Accept-Language: en
MIME-Version: 1.0
To: djgpp-workers AT delorie DOT com
Subject: Re: Useless warning from gcc 3.1
References: <200205271315 DOT PAA09349 AT lws256 DOT lu DOT erisoft DOT se>
Reply-To: djgpp-workers AT delorie DOT com

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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019