G
Guest
I have an implementation of linked lists coded entirely in macros, using
GNU C extensions __typeof__() and statement expressions. The flexibility
of this is that it allows creating your own node types and linking them
into a list very easily, without having to define type matched functions.
Type matching is done by making sure the anchor and node types do match.
This implementation creates a full circle doubly linked list in which the
last node links in the forward direction back to the first node, and also
first to last in the reverse direction. The anchor consists of a single
pointer to the first node.
To create a linked list, the program defines a struct with one of the macros
as a member, which creates 2 members to serve as the links. The struct type
(without struct keyword) is given as the argument on this macro. The program
creates an anchor as simply an lvalue of type pointer to the node struct and
initializes it with one of the macros. The lvalue is passed to the macros
directly. If the program has a pointer to the anchor, it would dereference
that pointer in the macro argument expression.
Here is the latest. The tarball includes a couple of test programs which
do only very simple tests for now.
The tarball:
http://phil.ipal.org/pre-release/list-0.0.5.tar.bz2
Direct browsing:
http://phil.ipal.org/pre-release/list-0.0.5/
Licensing is currently GPL. I plan to switch to BSD and/or MIT or other
similar unencumbered licensing when it is in final release.
GNU C extensions __typeof__() and statement expressions. The flexibility
of this is that it allows creating your own node types and linking them
into a list very easily, without having to define type matched functions.
Type matching is done by making sure the anchor and node types do match.
This implementation creates a full circle doubly linked list in which the
last node links in the forward direction back to the first node, and also
first to last in the reverse direction. The anchor consists of a single
pointer to the first node.
To create a linked list, the program defines a struct with one of the macros
as a member, which creates 2 members to serve as the links. The struct type
(without struct keyword) is given as the argument on this macro. The program
creates an anchor as simply an lvalue of type pointer to the node struct and
initializes it with one of the macros. The lvalue is passed to the macros
directly. If the program has a pointer to the anchor, it would dereference
that pointer in the macro argument expression.
Here is the latest. The tarball includes a couple of test programs which
do only very simple tests for now.
The tarball:
http://phil.ipal.org/pre-release/list-0.0.5.tar.bz2
Direct browsing:
http://phil.ipal.org/pre-release/list-0.0.5/
Licensing is currently GPL. I plan to switch to BSD and/or MIT or other
similar unencumbered licensing when it is in final release.