Entry tags:
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).
no subject
no subject
In both cases, something which might be expected to have no effect has been coded. Actually, given that excess arguments could be used for their side effects, there might be an argument that an empty format string is even less useful than excess arguments whose evaluation does something useful.
Also, given the same argument about format strings wrapped in macros, one could end up with a sequence like
printf("%s %d", StrArg1, IntArg1, IntArg2, IntArg3);
printf("%s %d %d", StrArg1, IntArg1, IntArg2, IntArg3);
printf("%s: (%d, %d)", StrArg1, IntArg1, IntArg2, IntArg3);
etc. being produced, and being warned about becuase not all the arguments get used.
something which might be expected to have no effect has been coded