Re: Explicit instantiation and static objects in different modules

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Aug 4, 2015, at 20:32, Alexander Monakov <amonakov@xxxxxxxxx> wrote:

> On Tue, 4 Aug 2015, Jonathan Wakely wrote:
>> The extern template tells the compiler it doesn't *need* to
>> instantiate the template, because it will be explicitly instantiated
>> in another translation unit. But that doesn't mean it *must not*
>> instantiate it. The compiler can choose to inline the function and in
>> that case it will implicitly instantiate it. That should be
>> unobservable because the One Definition Rule means that the implicitly
>> instantiated definition that gets inlined and the explicitly
>> instantiation definition in the other translation unit must be
>> identical. The Windows linkage model seems to break that assumption
>> ... so I don't know what the right behaviour is.
> 
> In light of that, perhaps it's best to structure code in a way that prevents
> implementation of a singleton from being visible in translation units that can
> be linked into different libraries.

Thanks for pointing this out. I’ll use __attribute__ (noinline) for functions with static variables.



[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux