Boost logo

Boost Users :

Subject: Re: [Boost-users] [Review] Formal Review: Boost.Move
From: John Dlugosz (JDlugosz_at_[hidden])
Date: 2010-05-24 16:03:38


I think that the point of the article (example 1 vs example 3) is that you are not allowed to cast or unionize pointers. You must store and fetch from a location that's declared as a union.

Now what if you cast, not from T1* to T2*, but from T1* to U*? Does the union itself have to be defined as a union, or can you cast the original typed pointer to the union pointer, perhaps as the parameter to a function call so that only the U* pointer is in scope and being dereferenced while T1* in the caller is dormant and assumed to be "changed" by virtue of the call.

Perhaps a close reading of the spec will indicate that a "barrier" is possible where two pointers are not used at the same time. I'm certain that works in practice though: upon calling foo(p);, the compiler assumes that *p has been changed. Within the body of foo, p is not used at all but q is used, which has the same address and different type. If p is not used, you don't have to worry about it being assumed not to change just because q is used. However, inlining complicates things.

I suppose to be ratified, a portable solution is needed. But individual compiler-specific solutions would implement the alias_cast by saying "yes this will alias" in a compiler-specific manner. The general solution is only for formality and bootstrapping a port to a different compiler/version, so it doesn't need to be that efficient.



From: boost-users-bounces_at_[hidden] [mailto:boost-users-bounces_at_[hidden]] On Behalf Of Neil Groves
Sent: Monday, May 24, 2010 1:14 PM
To: boost-users_at_[hidden]
Subject: Re: [Boost-users] [Review] Formal Review: Boost.Move


On Mon, May 24, 2010 at 6:59 PM, John Dlugosz <JDlugosz_at_[hidden]<mailto:JDlugosz_at_[hidden]>> wrote:
>
> The problem is not downcasting, but the fact that T is not rv<T> (the
> dynamic type of T is T, not rv<T>):
>
Reading the referenced article on C99 aliasing rules, perhaps what is needed is a alias_cast template that does it right (e.g. pass it through a union or use proper compiler-specific decorations).

That was my first thought too, but as far as I know all correct uses of a union would mandate a fully copy of the T instance. I think that the containment by pointer that was suggested by Steven Watanabe makes for a nice solution.

If you have a novel solution that uses a union while avoiding assignment to a new T instance I would be very interested.

Regards,
Neil Groves

TradeStation Group, Inc. is a publicly-traded holding company (NASDAQ GS: TRAD) of three operating subsidiaries, TradeStation Securities, Inc. (Member NYSE, FINRA, SIPC and NFA), TradeStation Technologies, Inc., a trading software and subscription company, and TradeStation Europe Limited, a United Kingdom, FSA-authorized introducing brokerage firm. None of these companies provides trading or investment advice, recommendations or endorsements of any kind. The information transmitted is intended only for the person or entity to which it is addressed and may contain confidential and/or privileged material. Any review, retransmission, dissemination or other use of, or taking of any action in reliance upon, this information by persons or entities other than the intended recipient is prohibited. If you received this in error, please contact the sender and delete the material from any computer.



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net