ewx: (geek)
Richard Kettlewell ([personal profile] ewx) wrote2009-04-27 02:49 pm

Stupid GCC

$ 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).

[identity profile] imc.livejournal.com 2009-04-27 03:03 pm (UTC)(link)
That would presumably have to be a macro though, not a function, to generate the warning.
simont: A picture of me in 2016 (Default)

[personal profile] simont 2009-04-27 03:06 pm (UTC)(link)
No, because if you're defining a function like that then you certainly use gcc's __attribute__((printf)) feature.