|
Boost : |
From: Phil Bouchard (philippe_at_[hidden])
Date: 2008-03-19 04:00:31
"Steven Watanabe" <watanabesj_at_[hidden]> wrote in message
news:47DFF458.7010409_at_providere-consulting.com...
[...]
> Which compilers? IMO, you shouldn't make the code even more obscure until
> it's known for certain to be a problem.
Well 0 is considered to be a null pointer, not a pointer to 0x0000. This
can potentially be replaced by "nullptr" in the next revision, which
shouldn't be assumed to be a pointer to 0x0000. Having a non-null constant
removes this nullness ambiguity.
I see there is a BOOST_PYTHON_OFFSETOF macro that exists and which uses this
technique. It is unfortunate offsetof() doesn't take a real
pointer-to-member address.
>> This address dissosiates
>> the pointer from an undefined behavior and is aligned for all types.
>>
>
> 5.5/4:
> "If the dynamic type of the object does not contain the member to which
> the pointer refers, the behavior is
> undefined."
"operator ->" can be used in an address constant expression without being
considered to be a dereference because of "operator &".
5.19/4:
An address constant expression is a pointer to an lvalue designating an
object of static storage duration, a string literal (_lex.string_), or a
function. The pointer shall be created explicitly, using the unary &
operator, or implicitly using a non-type template parameter of pointer
type, or using an expression of array (_conv.array_) or function
(_conv.func_) type. The subscripting operator [] and the class member
access . and -> operators, the & and * unary operators, and pointer casts
(except dynamic_casts, _expr.dynamic.cast_) can be used in the creation of
an address constant expression, but the value of an object shall not be
accessed by the use of these operators. [...]
-Phil
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk