Alf P. Steinbach <al***@start.no> wrote:
# On 22 Sep 2003 10:16:34 -0700,
mp****@tecnolink.com.br (Marcelo Pinto) wrote:
# >"Gregg" <gr***********@hotmail.com> wrote in message news:<xl*******************@newsread2.news.atl.ear thlink.net>...
# >>
# >> The "inline" keyword tells the compiler not to make the function name
# >> visible to other translation units. If you leave out this keyword, you might
# >> get linker errors indicating "duplicate symbol definitions" or something
# >> similar if the header is included in two different translation units. The
# >> "inline" is implied when the function is defined within the class
# >> definition.
# >
# >
# >Isn't this behavior of the static qualifier?
# With 'static' you get a local definition in each compilation unit.
# With 'inline' you get at most one definition, with a good compiler,
# unless the function is also 'static'.
# I'm not sure whether that last is a std. requirement on 'inline' or
# not, and won't look it up for you, but it's practice.
The 'inline' function is (firstly) required to be defined once per
compilation unit (in practice, it is required that inline functions be
DEFINED in header files). There are two characteristic things concerning
inline functions (which are not static simultaneously):
1. If a compiler decides to make inlining for this function, the linkage
does not concern it. However, since the compiler relies on function
definition from the compilation unit, it must be provided. If it is not,
this function falls under normal linkage, however... this is undefined
behavior.
2. If a compiler will not make inline version, this function falls under
normal linkage, as if there is no 'inline' modifier. However it means that
this function falls under so-called "weak linkage" (inline functions and
virtual method table are the only objects fallen under "weak linkage").
The difference between "strong linkage" and "weak linkage" is that in that
first case the linker will report an error due to definition conflict if
there are two object definitions found in separate module files (compilation
units; *.o/*.obj). For "weak linkage", the linker will not report this
error, however it is UNDEFINED, which definition (from which of module files)
will be effectively selected for the executable! Sometimes it even depends on
the order of file names passed to link command. That's why all inline function
definitions must be:
a) provided separately for each compilation unit
b) defined THE SAME in each compilation unit
Many good compilers (such as gcc) provide always an outline version for each
inline function. Remember also that the decision about expanding a function
inline depends also on compiler options.
Regards,
--
1 6 1 7 4 4 2 548 g4bc7a4 66z 3xt7w v1y z9p1 120 32
(( Michal "Sektor" Malecki w4 66 64 73 7564 24 5 v 34 4
)) ektor van Skijlen 1 5 5 1 844 a v r z 4
Software engineer, Motorola GSG Poland 1 2 2a 1 4
WARNING: Opinions presented by me on usenet groups are my personal opinions
ONLY and are not connected to the employer.