Re: puts() vs printf()
- From: "Stephen Sprunk" <stephen@xxxxxxxxxx>
- Date: Thu, 24 Aug 2006 17:56:30 -0500
"Schraalhans Keukenmeester" <firstname_dot_lastname@xxxxxxxxxxxxxxx>
wrote in message news:44edeb63$0$4517$e4fe514c@xxxxxxxxxxxxxxxxx
Stephen Sprunk wrote:
A modern compiler will notice when a single argument to printf()
contains no format specifiers and replace the call with puts() --
assuming it can strip the final '\n' at compile time.
I personally prefer using printf() for all output because then I
don't
have to deal with forgetting the implicit '\n' that puts() adds.
Slightly wandering OT: Tried my example (see my other response in this
thread) with gcc optimization enabled and ONLY when the string is a
literal or a #defined constant it looks as if execution times are
identical, which may be (and probably is) indicative of printf() being
replaced by the faster puts(). Declaring the string (even as const)
*char does not convince gcc to use puts() in stead of printf(), at
least
not here.
Would you say that gcc is a modern or old compiler based on this?
Sh.
My experience plus Racaille's report in another post lead me to say it's
modern, i.e. doing something reasonably clever as I described. It's
curious that it doesn't convert a printf(char*) to puts(char*) but does
with literals, but there may be some reason for that or it might be a
bug (at least in your version).
S
--
Stephen Sprunk "God does not play dice." --Albert Einstein
CCIE #3723 "God is an inveterate gambler, and He throws the
K5SSS dice at every possible opportunity." --Stephen Hawking
--
Posted via a free Usenet account from http://www.teranews.com
.
- Follow-Ups:
- Re: puts() vs printf()
- From: CBFalconer
- Re: puts() vs printf()
- References:
- puts() vs printf()
- From: Debaser
- Re: puts() vs printf()
- From: Stephen Sprunk
- Re: puts() vs printf()
- From: Schraalhans Keukenmeester
- puts() vs printf()
- Prev by Date: Re: i'm a little confused
- Next by Date: Re: array initialization
- Previous by thread: Re: puts() vs printf()
- Next by thread: Re: puts() vs printf()
- Index(es):
Relevant Pages
|