>>>> "Hrvoje" == Hrvoje Niksic
<hniksic(a)srce.hr> writes:
Hrvoje> 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.
Hrvoje> 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)
Hrvoje> Will this not choke on compilers that don't support the inline
Hrvoje> keyword? Does config.h.in #define inline to naught when inline is not
Hrvoje> available?
It should. That's what AC_C_INLINE in configure.in is supposed to determine.
> One reason this has never been done is that it should be
unnecessary
> with most modern compilers at sufficient levels of optimizations.
Hrvoje> It *is* necessary. Some people don't want to use -O3 because it
Hrvoje> generates much more code. On the other hand, -O2 will produce a
Hrvoje> funcall for each mention of digit_to_number(), which I decidedly don't
Hrvoje> want.
Hrvoje> Using the inline keyword sparingly has the advantage of specifying
Hrvoje> exactly which functions you want inlined, regardless of the
Hrvoje> optimization level.
> Both gcc -O3 and Sun cc -xO4 do inlining of static functions
> automatically.
Hrvoje> I know, but see above.
> In fact, inline, like register, is merely a hint to the compiler.
Hrvoje> There is a difference.
Conceptually, I don't see any difference. Sufficiently good compilers
should obsolete use of register and inline.
> 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.
Hrvoje> Again, see above. -O3 makes the compiler inline many other functions,
Hrvoje> 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.
Hrvoje> I agree with Steve. -O3 generates much more code.
I'm surprised. These days it's hard to play the game `we are smarter
than the compiler'.
I encourage you to go ahead and experiment with changing functions
which are currently `static' to `static inline'. See what `inline' is
defined to in config.h with your compiler.
Martin