This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Statement incorrect in doc


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) )

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



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]