Wrong pointer calculation without casting on struct

2015-02-05 Thread tcak via Digitalmars-d-learn
I am on 64-bit Linux. I defined a struct that it 8 bytes in total. align(1) struct MessageBase{ align(1): ushort qc; ushort wc; ushort id; ushort contentLength; void[0] content; } I defined a function in this struct that tries to set a pointer to "conte

Re: Wrong pointer calculation without casting on struct

2015-02-05 Thread tcak via Digitalmars-d-learn
On Friday, 6 February 2015 at 03:59:51 UTC, tcak wrote: I am on 64-bit Linux. I defined a struct that it 8 bytes in total. align(1) struct MessageBase{ align(1): ushort qc; ushort wc; ushort id; ushort contentLength; void[0] content; } I defined a funct

Re: Wrong pointer calculation without casting on struct

2015-02-05 Thread Baz via Digitalmars-d-learn
On Friday, 6 February 2015 at 04:10:08 UTC, tcak wrote: On Friday, 6 February 2015 at 03:59:51 UTC, tcak wrote: I am on 64-bit Linux. I defined a struct that it 8 bytes in total. align(1) struct MessageBase{ align(1): ushort qc; ushort wc; ushort id; ushort cont

Re: Wrong pointer calculation without casting on struct

2015-02-06 Thread Ali Çehreli via Digitalmars-d-learn
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). > write