This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: patch to suggest putc/fputs over printf("string") or printf("\n")


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]