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

Kaveh R. Ghazi
Sun Jan 31 23:58:00 GMT 1999

 > From: Jason Merrill <>
 > >>>>> Kaveh R Ghazi <> writes:
 >  > to putc which is a macro expanded to several statements.  I think we can
 >  > do appropriate checks on -Os to decide whether to do these size-vs-speed
 >  > optimizations, or to call fputc (a function) instead of putc (a macro.)
 > Erm, how could the compiler turn a printf call into a macro expansion?  The
 > compiler doesn't know anything about macros.  I suppose it could have its
 > own concept of putc...
 > Jason

	We'd have to get cpp to cooperate, but suppose cpp emitted
something like the following when we're optimizing printf functions.
(Or we could just have fixincludes stick this in stdio.h.)

#ifdef __OPTIMIZE__
# ifdef __OPTIMIZE_SIZE__  /* Set by -Os */
static inline int __gcc_putc(char c, FILE* stream) {return fputc (c, stream);}
static inline int __gcc_putc_stdio(char c) {return fputc (c, stdio);}
# else
static inline int __gcc_putc(char c, FILE* stream) {return putc (c, stream);}
static inline int __gcc_putc_stdio(char c) {return putc (c, stdio);}
# endif /* __OPTIMIZE_SIZE__ */
#endif /* __OPTIMIZE__ */

	In this case, we could replace these:

 > printf ("\n");
 > fprintf (stderr, "\n");

with these:

 > __gcc_putc_stdio ('\n');
 > __gcc_putc ('\n', stderr);

and then these inline functions get expanded to the putc macro's
definition or the fputc function call depending on whether the user
selected -Os. 

Kaveh R. Ghazi			Engagement Manager / Project Services		Icon CMT Corp.

More information about the Gcc mailing list