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: law at cygnus dot com
- Subject: Re: patch to suggest putc/fputs over printf("string") or printf("\n")
- From: "Kaveh R. Ghazi" <ghazi at caip dot rutgers dot edu>
- Date: Sun, 10 Jan 1999 12:32:17 -0500 (EST)
- Cc: egcs-patches at cygnus dot com, egcs at cygnus dot com
> From: Jeffrey A Law <law@hurl.cygnus.com>
>
> In message <199901100718.CAA06898@caip.rutgers.edu>you write:
> > Sun Jan 10 01:10:26 1999 Kaveh R. Ghazi <ghazi@caip.rutgers.edu>
> >
> > * c-common.c (check_format_info): Suggest replacing calls to
> > printf, fprintf and sprintf with putc/fputs or strcpy if no
> > arguments appear after the format specifier.
>
> Actually, I'd consider a patch which conditionally converted them for the
> user. We've kicked that idea around quite a bit inside Cygnus, but never
> got excited enough to implement it. See also:
>
> http://www.nullstone.com/htmls/category/printf.htm
That URL is useful in that it says the optimization is
valid/legal and has significant benefits. So this appears worth
pursuing. (I note however that the example it gives appears wrong
because it substitutes puts() which appends an extra newline thus
changing the program's behavior!) Its also short on details like what
transformations (beyond the obvious ones) are worth doing.
Getting started, I would like to get more guidance on how this
would need to be implemented in gcc. (Assume minimal background on my
part on gcc's guts.) If this has been kicked around perhaps some legwork
has already been done, or at least someone can share the
ideas/approaches that were kicked. That would give me a starting point.
Thanks,
--Kaveh
PS: If we do this optimization in cc1, then what about changing
printf("\n") into putc('\n') ? Since putc is a macro we can't do this
cause we've lost the macro definition expansion? I guess fputc would
have to suffice (?)
--
Kaveh R. Ghazi Engagement Manager / Project Services
ghazi@caip.rutgers.edu Icon CMT Corp.