Boost logo

Boost :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2003-02-19 12:00:01


Alexander Terekhov wrote:
> Peter Dimov wrote:
>>
>> Ken Hagan wrote:
>>> Peter Dimov wrote:
>>>>
>>>> &k does not exist yet at compile-time (in a pointer to int form),
>>>> when templates are instantiated.
>>>
>>> It doesn't have to. We're instantiating a template, not calling a
>>> function, so if "&k" has the type "pointer to thread-local int" then
>>> the compiler knows that and can instantiate the appropriate code.
>
> Please define "appropriate code". Please see the added 2 lines below.

[...]

>> template<uintptr_t * p> struct C
>> {
>> void f()
>> {
>> std::cout << " p: " << p << ": " << *p << std::endl;
> static const uintptr_t * P = p;
> std::cout << " P: " << P << ": " << *P << std::endl;
>> }
>> };

Output:

 p: 00143204: 2024
 P: 00143204: 2024
&k: 00143204: 2024
 p: 00143224: 2036
 P: 00143204: 2024
&k: 00143224: 2036
 p: 00143244: 2012
 P: 00143204: 2024
&k: 00143244: 2012

I must admit that I didn't expect even for p to be different across threads.


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