Mail Archives: djgpp/2001/07/23/08:45:15
Andrew Clifton <andyclifton AT cs DOT comnospam> wrote:
> Both files will compile fine. When I try to link them into an
> executable, however, I get a multiple-definition link error.
That's to be expected, to some extent.
> If I
> change some_function to be "extern inline" I get undefined reference
> link errors.
That almost certainly means that you didn't turn on optimization, or
the function marked "inline" was judged not inline-able by the
compiler.
The official method is to have two copies of the function's source:
one marked "extern inline", in a header file, the other unmarked, in
one of the source files. It can be done without the second copy, by
some preprocessor magic to remove the 'extern', while compiling that
"mother" sourcefile.
And you have to compile with optimization turned on. This will inline
the function from the source found in the header file, where
applicable. For those cases that can't be inlined, or where the
optimizer believes it to be a bad idea, it'll call the separate,
non-inlined version in the source file.
> Using "static inline" works, but I have a feeling that
> it might actually be including a copy of the function in the object
> file for each source.
Not each source --- only those that actually use it. For the others,
you get a 'defined "static" but not used' warning.
--
Hans-Bernhard Broeker (broeker AT physik DOT rwth-aachen DOT de)
Even if all the snow were burnt, ashes would remain.
- Raw text -