Why does gcc -Wall give warning about zero-length format string?

The fact that GCC issues a warning usually has nothing to do with whether the construct is legal C, but whether the GCC developers consider it either a likely indication that you meant something other than what you write, or just bad style. Here are some examples:

  • if (x = 0) — you almost surely meant if (x == 0).
  • printf(str) — you almost surely meant either fputs(str, stdout) or printf("%s", str); as written, the code is very dangerous.
  • if (foo == bar & MASK) — you almost surely meant if (foo == (bar & MASK)).

etc.

In your case, I think GCC is questioning why you’re calling sprintf(String, "") to do the equivalent of String[0]=0; (the latter is much shorter, faster, and clearer).

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)