This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: patch to suggest putc/fputs over printf("string") or printf("\n")
- To: arvinds at mit dot edu
- Subject: Re: patch to suggest putc/fputs over printf("string") or printf("\n")
- From: Marc Espie <espie at quatramaran dot ens dot fr>
- Date: Mon, 11 Jan 1999 21:23:27 +0100
- Cc: egcs at egcs dot cygnus dot com
- Organization: none
- References: <199901111943.LAA00852@kankakee.wrs.com>
- Reply-To: Marc dot Espie at liafa1 dot liafa dot jussieu dot fr
In article <19990111145131.A2087@anjala.mit.edu> you write:
>I don't get this. How are putc, fputs, strcpy any _less_ readable than
>their printf equivalents?
The compiler is myopic, it may suggest that fputs is better on the last
line of the following code fragment:
if (flag)
fprintf(file, "This is the %d case\n", i);
else
fprintf(file, "Nothing about it\n");
whereas the programmer may believe in using only printf's for symetry.
As another case, at one point, the patch source code did use code
that held:
#define try(f, a1, a2, a3) snprintf(buf, sizeof buf, f, a1, a2, a3)
which was then invoked as try("%s/%s/%s", one, two, three) or
try("%s/RCS/%s", one, "", two)
The compiler might also see fit to warn you for that second use...
Basically, adding any warning to -Wall that flags perfectly correct code
as potentially bad is not a good idea: it breaks Makefiles that use
-Wall -Werror gratuitously.
As far as C code goes, changing printf to fputs for simple formats is
perfectly leggit. Amiga SAS/C has been doing it for ages... :)