Boost logo

Boost :

From: Jeff Garland (jeff_at_[hidden])
Date: 2007-04-05 10:00:35


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.

Jeff


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