[A86] Re: SDCC v2.3.0


[Prev][Index][Thread]

[A86] Re: SDCC v2.3.0




I don't know if it is in the standard, but I've never seen anything declare
functions as extern.  It's legal, but it seems to be redundant (like the
auto keyword).  With the -O3 option, gcc will inline functions.  Unless the
function is declared as static, the compiler will generate a separate
version of the function, even though it may never be called in the module
(which is why it is good practice to use always use static when applicable).

gcc's inline keyword for C works differently than the C++ inline keyword.
In C++, if a function is marked inline, then a separate version of it will
not be generated.  Using extern with inline does not cause a separate
version to be generated, so I'm not sure of what effect it has, if any.  I
don't have ready access to the standard or a reference, but I think that
inline makes the function static.  gcc's inline keyword for C generates a
separate version of the function, unless it is marked static and
optimizations are enabled.  This should be consistent with the automatic
function inlining with -O3 or -finline-functions, as it is just a hint to
the compiler.

A couple relevant sections from the gcc man page are pasted below:

 -finline-functions
              Integrate  all simple functions into their callers.
              The compiler heuristically decides which  functions
              are  simple  enough to be worth integrating in this
              way.

              If all calls to a given  function  are  integrated,
              and  the function is declared static, then GCC nor­
              mally does not output  the  function  as  assembler
              code in its own right.

       -fkeep-inline-functions
              Even if all calls to a given function are integrat­
              ed,  and the function is declared static, neverthe­
              less output a separate run-time callable version of
              the function.

> Doesn't extern guarantee that a non-inline version of the routine will
> exist?
>
> If not, sounds like something similar to volatile (essentially opposite
> of register) should exist for functions.






References: