$include_dir="/home/hyper-archives/boost/include"; include("$include_dir/msg-header.inc") ?>
Subject: Re: [boost] [AFIO] Formal review
From: John Bytheway (jbytheway+boost_at_[hidden])
Date: 2015-09-02 05:31:34
On 2015-09-01 18:42, Niall Douglas wrote:
> Please do correct me if I am wrong, but I had thought that this is
> defined behaviour:
>
> int a=5;
> void *b=(void *)(size_t) a;
> int c=(int)(size_t) b;
> assert(c==a);
>
> This is certainly a very common pattern in C.
I believe this is implementation-defined. Based on N3797
[expr.reinterpret.cast], paragraph 5:
"A value of integral type or enumeration type can be explicitly
converted to a pointer. A pointer converted to an integer of sufficient
size (if any such exists on the implementation) and back to the same
pointer type will have its original value; mappings between pointers and
integers are otherwise implementation-defined."
The behaviour that is defined (pointer to integer and back) is the
reverse of the one you want.
John Bytheway