Martin Buchholz <martin(a)xemacs.org> writes:
Hrvoje> How do I turn that junk off and simply say that I want
this function
Hrvoje> to be inlined, in a portable way (portable as in "ignore it on
Hrvoje> compilers that don't support the `inline' keyword)?
Currently all explicitly inline functions exist only in header
files, where they are defined via INLINE, which takes care of the
thorny issues of multiple definitions of the function in gcc via
inline.c.
I know that, but I don't *want* to do this.
For functions only used in a .c file, you could do (untested)
static inline int
digit_to_number (int character, int base)
Will this not choke on compilers that don't support the inline
keyword? Does config.h.in #define inline to naught when inline is not
available?
One reason this has never been done is that it should be unnecessary
with most modern compilers at sufficient levels of optimizations.
It *is* necessary. Some people don't want to use -O3 because it
generates much more code. On the other hand, -O2 will produce a
funcall for each mention of digit_to_number(), which I decidedly don't
want.
Using the inline keyword sparingly has the advantage of specifying
exactly which functions you want inlined, regardless of the
optimization level.
Both gcc -O3 and Sun cc -xO4 do inlining of static functions
automatically.
I know, but see above.
In fact, inline, like register, is merely a hint to the compiler.
There is a difference.
Are you sure you know better than the compiler whether inlining
digit_to_number is worth it? Actually, in this case, both you and
the compiler should be able to figure it out, since it's trivial.
Again, see above. -O3 makes the compiler inline many other functions,
which I may or may not want.
# pgcc optimized build:
$ nm data.o | g digit_to_number
$
# pgcc debug build:
$ nm data.o | g digit_to_number
00003ea0 t digit_to_number
$
We should make -O3 the default optimization flag for gcc. In fact,
I submitted a patch that did this, but Steve REJECTED it.
I agree with Steve. -O3 generates much more code.
--
Hrvoje Niksic <hniksic(a)srce.hr> | Student at FER Zagreb, Croatia
--------------------------------+--------------------------------
Your lucky number today is 29842924728. Look for it everywhere.