Re: sockfd_lookup

Eric.Schenk@dna.lth.se
Sun, 11 May 1997 00:03:24 +0200


"James R. Leu" <jleu@chaos.coredcs.com> writes:
>Then why do I get
>
>netmirr.o(.text+0x170): undefined reference to `sockfd_lookup'
>
>when I leave the 'extern' in(using gcc 2.7.2.1)? When I remove the 'extern'
>it compiles and works fine.

You neglected to mention that the body of the function is also present
with the declaration. In which case they are not the same.
Without the extern the function is actually a part of the local source file.
With the extern the function only gets inserted inline in the local file
but does not get compiled in as a separate function. Now the tricky bit,
gcc only does inlining when you turn on optimization. If you compile
the above without optimization but with "extern __inline__" then the
code never appears anywhere (gcc things the code will be linked in
from another file), so you loose.

The "extern __inline__" form gets used when you want to have a bit of
inlined code that never appears as a callable routing itself. You just
need to make sure you have optimization turned on or it won't work.

-- 
Eric Schenk                               www: http://www.dna.lth.se/~erics
Dept. of Comp. Sci., Lund University          email: Eric.Schenk@dna.lth.se
Box 118, S-221 00 LUND, Sweden   fax: +46-46 13 10 21  ph: +46-46 222 96 38