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

Kent Vander Velden graphix@iastate.edu
Mon Jan 11 15:20:00 GMT 1999


>> Do people think that the warnings appearing below would be useful?
>
>> cccp.c:1635: warning: suggest using `putc' instead of `fprintf'
>> cccp.c:2058: warning: suggest using `fputs' instead of `fprintf'
>> cccp.c:10232: warning: suggest using `strcpy' instead of `sprintf'
>
>No, I don't like these at all.  I think it would be more useful to fix
>the compiler to transform the printf call into a putc call, the hard
>thing about it is you really want to do this early so that you can get
>at the marcos, if any.  Anyway, even if one didn't, I think it would
>still be useful.

  The warnings would seem to be more beneficial in the long term.  They
would help to enlighten developers and give them the chance to improve
their code for all compilers.

>The reasoning behind not liking these, is it unduly encourages people
>to save five clock cycles at the expense of readable code.  If it goes
>in, please don't have it on by default or -Wall.

  This is likely because of just how people are used to performing a
task.  They have always used printf("%s\n", string) and expect this.
Unfortunately these expectations only encourage continuation of the bad
practice.  After all, if you know the functions, how is puts() any less
readable than printf()?  Actually, it would seem to emphasize the
intention.

---
Kent Vander Velden
kent@iastate.edu



More information about the Gcc-patches mailing list