Boost logo

Boost :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2007-04-05 10:43:11


Jeff Garland wrote:
> Anthony Williams wrote:
>> Iulian M <eti_at_[hidden]> writes:
>>
>
>>> IIRC if get_instance() will be inlined and 2 translation units will
>>> have their own copy of get_instance() then there will be two st
>>> instances in the finall app... witch in case of a singleton is BAD.
>>>
>>> ps: i only had 2 zips of coffee so i might be missing something ...
>>
>> Have another cup of coffee then, because you are missing something.
>>
>> The compiler is required to ensure that there is only one copy of
>> statics declared in inline functions, even if that function is
>> defined in more than one translation unit, because otherwise you get
>> precisely the problem you describe.
>
> It can, in fact, trivially happen. Try linking in a couple static
> libs on windows that call this function...you'll get 2.

You will on MSVC 6.0 because of a compiler bug. Inlining doesn't change
semantics.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk