Boost logo

Boost :

From: Alexander Terekhov (terekhov_at_[hidden])
Date: 2003-02-21 12:41:46


David Abrahams wrote:
>
> Gabriel Dos Reis <gdr_at_[hidden]> writes:
>
> > David Abrahams <dave_at_[hidden]> writes:
> >
> > | I disagree with your conclusion. As I've said elsewhere, &k can be a
> > | compile-time constant in the same way that &X::k is a compile-time
> > | constant.
> >
> > Certainly, you've said that. But that assertion by itself does not
> > constitute a proof of the well-foundness of the attempted analogy or
> > whether the analogy actually constitutes a proof.
>
> It's not intended to be proof in the mathematical sense; I doubt I
> have the energy for that ;-), though I think MSVC probably constitutes
> an existence proof.

Yeah. Indeed: <http://tinyurl.com/673e>

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vccore/html/_core_rules_and_limitations_for_tls.asp

"....
 The address of a thread local object is not considered constant,
 and any expression involving such an address is not considered
 a constant expression. In standard C, the effect of this is to
 forbid the use of the address of a thread local variable as an
 initializer for an object or pointer. For example, the
 following code will be flagged as an error by the C compiler:

   #define Thread __declspec( thread )
   Thread int tls_i;
   int *p = &tls_i; //This will generate an error in C.

 This restriction does not apply in C++, however. Because C++
 permits dynamic initialization of all objects, you can
 initialize an object with an expression that uses the address
 of a thread local variable. This is accomplished in the same
 way as the construction of thread local objects. For example,
 the code shown above will not generate an error when compiled
 as a C++ source file. Note that the address of a thread local
 variable is valid only as long as the thread in which the
 address was taken still exists.
 ...."

regards,
alexander.

P.S. Kinda-funny stuff: "C++ does not allow such dynamic
initialization of thread data because of possible future
enhancements to the thread local storage facility."


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