Humm... I will post an example LIFO linked collection API (e.g. stack)
in a day or two. We should be able to tear it apart into something
usable. A simple standardized API wrt this newsgroup could be
beneficial. Well, any question that deals with common/trivial
collection abstractions can be directed at the various implementations
of this newsgroups standardized API.
There's already a BSD-licensed implementation of various 'collections'
of objects, including:
* Singly-linked lists.
* Doubly-linked lists.
* Tail queues.
* Singly-linked tail queues.
Maybe you could start with something like this, and extend it a bit?
The supported data structures are not really great in number, but they
are still quite useful in many cases.
The source for the macros I'm referring to is part of the source tree of
the various BSDs out there, and parts of it have already made their
way into the Linux kernel too. See for example:
http://cvsweb.freebsd.org/src/sys/sys/queue.h
The documentation of the existing macros, in groff_mdoc(7) format, is
also available at:
http://cvsweb.freebsd.org/src/share/man/man3/queue.3
With the small exception of the STAILQ_LAST() macro -- which depends on
a call to__offsetof() to work properly -- the rest of the macros are
fairly easy to port/reuse in at least the following systems:
* FreeBSD, using various GCC versions
* FreeBSD, using the Intel C compiler
* OpenBSD, using GCC
* NetBSD, using GCC
* Solaris 8, 9 and 10, using either GCC or Sun Studio
* Linux, using various GCC versions
This list is not exhaustive, but it only includes the systems I have
used so far.
I'm not sure if macros are the appropriate way to go, but they may be
useful as you try to come up with a set of 'collection' structures for
standard C. I know that they have been very useful for me during the
last few years, but YMMV
- Giorgos