>>>> "Hrvoje" == Hrvoje Niksic
<hniksic(a)srce.hr> writes:
Hrvoje> OK, say I want to inline a function for efficiency. A typical example
Hrvoje> is digit_to_number() in data.c. However, saying
Hrvoje> statc INLINE int
Hrvoje> digit_to_number ...
Hrvoje> does not appear to work, because INLINE does some demented tricks with
Hrvoje> extern and stuff.
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.
For functions only used in a .c file, you could do (untested)
static inline int
digit_to_number (int character, int base)
One reason this has never been done is that it should be unnecessary
with most modern compilers at sufficient levels of optimizations.
Both gcc -O3 and Sun cc -xO4 do inlining of static functions
automatically. In fact, inline, like register, is merely a hint to
the compiler.
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.
# 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.
Martin