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: jason 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: Sat, 16 Jan 1999 20:27:02 -0500 (EST)
- Cc: egcs-patches at cygnus dot com, egcs at cygnus dot com, egcs at tantalophile dot demon dot co dot uk, law at cygnus dot com
> From: Jason Merrill <jason@cygnus.com>
>
> >>>>> Kaveh R Ghazi <ghazi@caip.rutgers.edu> 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
--
Kaveh R. Ghazi Engagement Manager / Project Services
ghazi@caip.rutgers.edu Icon CMT Corp.