From: Andrew Pinski <pinskia@physics.uc.edu>
To: Rob Aberg <roa@charter.net>
Cc: gcc@gnu.org
Subject: Re: Statement incorrect in doc
Date: Mon, 28 Oct 2002 05:58:00 -0000 [thread overview]
Message-ID: <02DD2E77-E9DB-11D6-BD0B-000393122612@physics.uc.edu> (raw)
In-Reply-To: <20021027132815.4b8a4d0e.roa@charter.net>
On Sunday, Oct 27, 2002, at 10:28 US/Pacific, Rob Aberg wrote:
> While looking in Google for discussions on stategies for optionally
> inlining C functions in a semi-portable way, I ran across your online
> doc:
>
> http://gcc.gnu.org/onlinedocs/gcc/Inline.html
>
> The section heading is "An Inline Function is As Fast As a Macro".
> That's not entirely true. Often, an inline function is faster: if a
> macro uses its "input arg" more than once and the arg is an expression,
> the arg-expression is evaluated multiple times unless other
> optimizations in gcc are active and see the common subexpression and
> eliminate it. Consider this macro:
>
> #define my_min(X,Y) ( ((X) < (Y)) ? (X) : (Y) )
Because you can use gcc extensions to make it the same:
#define my_min(x,y) ({ __typeof__(x) x1=x; __typeof__(y) y1=y;
((x1<y1)?x1:y1) })
This will be the almost same as the inline function (in c++ at least
because c does not have a concept of a template):
template <typename __t> __t min(__t x, __t y)
{
return (x<y)?x:y;
}
>
> It will evaluate either the (X) or the (Y) expression twice. It can be
> arbitrarily worse for nested macros. Or am I just missing something?
>
>
> Now that I am reminded, I'll order this one as well -- I have the gdb
> book, it is very well written...
>
>
>
> Thanks,
>
> Rob Aberg
> Grafton, MA
>
>
>
>
prev parent reply other threads:[~2002-10-27 18:36 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-10-28 5:30 Rob Aberg
2002-10-28 5:58 ` Andrew Pinski [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=02DD2E77-E9DB-11D6-BD0B-000393122612@physics.uc.edu \
--to=pinskia@physics.uc.edu \
--cc=gcc@gnu.org \
--cc=roa@charter.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).