PMyLinkedHead =^TMyLinkedHead;// Forward declaration pointer to the record
TMyLinkedHead =record
Prev, Next: PMyLinkedHead;
end;
TData =record
// ...
end;
TListEntry =record
Head: TMyLinkedHead;
Data: TData;
end;
Note you must then write
ListEntry.Head.Next^ or ListEntry.Data.Foo...
I do not know what you want to do on top of that.
Also there is one point I do not know the exact answer, so you may need to google it.
Compilers "align" they fields (the add padding).
record a: byte; b: int64; end; will create a structure that may have 3 or 7 empty bytes after "a".
I do not know what gcc does... You can change that by using "packed", or changing compiler settings. But I do not have the details...
The point is, if you call a c-library, it does not care how your code looks. It cares where in memory each bit of the data is.
you should change the "title" of your post. Edit your first post in this thread, and change the title: "Linked lists" or "self referring structures" ....
Title: Re: [WANTED] Intrusive data structures
Post by: julkas on May 19, 2019, 03:38:02 pm
Another Intrusive Linked List example in C - https://www.cs.helsinki.fi/group/cpro/harj5_13.pdf. It's based on C offsetof, container_of macros (https://en.wikipedia.org/wiki/Offsetof).