[fpc-pascal] Translate C code

Ryan Joseph ryan at thealchemistguild.com
Sat Jan 6 09:59:27 CET 2018



> On Jan 6, 2018, at 1:49 PM, Karoly Balogh (Charlie/SGR) <charlie at scenergy.dfmk.hu> wrote:
> 
> type
>  PMyStruct = ^TMyStruct;
>  TMyStruct = record
>    some, fields: integer;
>    next: PMyStruct;
>  end;
> 
> function MEMNEXT(x: Pointer): PMyStruct;
> begin
>  MEMNEXT:=PMyStruct(PByte(x)-PByte(@(PMyStruct(nil)^.next)));
> end;

I’m curious about how this is intended to be used. What would the value of x be? This looks like a confusing way to write sizeof(TMyStruct) - Sizeof(pointer) but I’m confused myself.

Also why does @(PMyStruct(nil)^.next not crash? Dereferencing and taking the addressing of a nil pointer sounds like a bad idea.

Regards,
	Ryan Joseph




More information about the fpc-pascal mailing list