patch to suggest putc/fputs over printf("string") or printf("\n")
Kaveh R. Ghazi
Sun Jan 10 09:32:00 GMT 1999
> From: Jeffrey A Law <email@example.com>
> In message < 199901100718.CAA06898@caip.rutgers.edu >you write:
> > Sun Jan 10 01:10:26 1999 Kaveh R. Ghazi <firstname.lastname@example.org>
> > * 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:
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.
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
email@example.com Icon CMT Corp.
More information about the Gcc-patches