when I try to compile fprintf(stderr,Usage)
on Ubuntu I got this error:
error: format not a string literal and no format arguments [-Werror=for
It is perfectly correct to use fprintf()
with only two arguments. As the function definition clearly indicates, all arguments after the second are optional.
When the second argument does not contain a format clause, this warning actually becomes a bug, one that was introduced into GCC because of a BAD assumption that the second argument to fprintf()
would always contain a format clause. There is nothing that is true about that assumption. This was a flawed decision, a bug, that was repaired in newer versions of GCC, which actually inspect the second argument to ensure the proper number and types of additional arguments are present when required.
Mixing fputs()
and fprintf()
calls is asking for bugs. Plus it just makes the code uglier. It is much cleaner to use fprintf()
everywhere, so long as you are also using a recent and sane GCC.
The moral of this story is simple: Never modify good code to make a bad compiler happy.