Wrong pointer calculation without casting on struct
Ali Çehreli via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Thu Feb 5 23:58:32 PST 2015
On 02/05/2015 07:59 PM, tcak wrote:
> writeln( "Without: ", (&this + id.offsetof) );
In pointer arithmetic, the increment value means "that many *objects*
away", not "than many bytes away".
Since id.offsetof is 4, you are calculating 4 MessageBase objects away
(4*8==32 bytes away).
> writeln( "With : ", (cast(size_t)&this + id.offsetof) );
That is not pointer arithmetic, so the increment is just 4.
32 - 4 == 28.
Ali
More information about the Digitalmars-d-learn
mailing list