Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C++ (http://www.velocityreviews.com/forums/f39-c.html)
-   -   linking instanciated inline functions (http://www.velocityreviews.com/forums/t459801-linking-instanciated-inline-functions.html)

Sylvain Audi 01-13-2007 02:06 AM

linking instanciated inline functions
 
I know that declaring a function as inline does not imply the function
will actually be inlined (e.g. recursive functions, etc...).

In that case, where would the function be instanciated?
My guess is that it would be instanciated in the compilation unit that
uses it. But in this case, several compilation units that use the same
inline function would mean that the linker has to deal with several
instances of the same function: shouldn't the linker fail on this?

So:
- are the linkers required to "optimize" and remove duplicate instances
of a function?
- do compilation units that require instanciating an inline function do
it only locally, not exposing the instance to the linker?

I actually never faced any such problem, as my compiler/linker handles
it somehow, but I was simply wondering what was going on really...

Ian Collins 01-13-2007 02:20 AM

Re: linking instanciated inline functions
 
Sylvain Audi wrote:
> I know that declaring a function as inline does not imply the function
> will actually be inlined (e.g. recursive functions, etc...).
>
> In that case, where would the function be instanciated?
> My guess is that it would be instanciated in the compilation unit that
> uses it. But in this case, several compilation units that use the same
> inline function would mean that the linker has to deal with several
> instances of the same function: shouldn't the linker fail on this?
>
> So:
> - are the linkers required to "optimize" and remove duplicate instances
> of a function?


The C++ Standard requires at most one copy in the entire program of a
non-static inline function, so in effect, yes.

> - do compilation units that require instanciating an inline function do
> it only locally, not exposing the instance to the linker?
>

Some compilers may do this to improve build times, but it isn't standard
conforming. I tend to default to this option with my compiler for
development builds where compiling with debug disables function inlining.

--
Ian Collins.


All times are GMT. The time now is 01:45 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.