Stupid GCC

Apr. 27th, 2009 02:49 pm
ewx: (geek)
[personal profile] ewx
$ cat t.c
#include <stdio.h>
int main(void) { return printf(""); }
$ gcc -Wall -c t.c
t.c: In function ‘main’:
t.c:2: warning: zero-length printf format string
$ gcc -Wall -Wno-format-zero-length -c t.c
$ gcc --version
gcc (Debian 4.3.2-1.1) 4.3.2
Copyright (C) 2008 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Can anyone offer a plausible reason why:

  • -Wformat-zero-length is on by default (i.e. implied by -Wformat and thus by -Wall)?
  • Why it exists at all?

FTAOD, empty format strings are perfectly legitimate (and the GCC Manual knows this).

(no subject)

Date: 2009-04-27 02:13 pm (UTC)
simont: A picture of me in 2016 (Default)
From: [personal profile] simont
The obvious case is when your format strings are generated at compile time by a system of cpp macros, and some of them come out empty.

(I've often thought that a lot of compiler warnings need a special case "unless it was generated by a macro", because the sorts of things that indicate a probable user error when they appear in handwritten code are often very similar to the sorts of things that are perfectly sensible preprocessor output.)
Edited Date: 2009-04-27 02:14 pm (UTC)

(no subject)

Date: 2009-04-27 02:24 pm (UTC)
ext_8103: (Default)
From: [identity profile] ewx.livejournal.com
An "unless unreachable" clause in particular ought to be a no-brainer, and would have saved at least two false positives that I can remember.

(no subject)

Date: 2009-04-27 02:33 pm (UTC)
simont: A picture of me in 2016 (Default)
From: [personal profile] simont
Or "unless I use the general-purpose warning-suppression escape". Things like the extra pair of parentheses around assignments in if statements are all very well, but really one would like an __I_meant_to_do_this(arbitrary C code) sort of construction which would work equally well against any warning, with which you could then liberally pepper your complicated macro setups.

(In a really ideal world it would also work equally well in any compiler, but the boat is well and truly missed on that one.)

July 2025

S M T W T F S
  12345
6789101112
13141516171819
202122232425 26
2728293031  

Most Popular Tags

Expand Cut Tags

No cut tags