-/*!
- * Iterate over all nodes in a list. This statement defines a for cicle
- * accepting the following parameters:
- * \param n node pointer to be used in each iteration
- * \param l pointer to list
+/** Declare a typesafe node for structures of type \a T. */
+#define DECLARE_NODE_TYPE(T) \
+ typedef struct T##Node { T *succ; T *pred; } T##Node
+
+/** Template for a list of \a T structures. */
+#define DECLARE_LIST_TYPE(T) \
+ DECLARE_NODE_TYPE(T); \
+ typedef struct T##List { \
+ T##Node head; \
+ T##Node tail; \
+ } T##List
+
+#define NODE_TYPE(T) T##Node
+#define LIST_TYPE(T) T##List
+
+/**
+ * Get a pointer to the first node in a list.
+ *
+ * If \a l is empty, result points to l->tail.
+ */
+#define LIST_HEAD(l) ((l)->head.succ)
+
+/**
+ * Get a pointer to the last node in a list.
+ *
+ * If \a l is empty, result points to l->head.
+ */
+#define LIST_TAIL(l) ((l)->tail.pred)
+
+// TODO: move in compiler.h
+#if COMPILER_TYPEOF
+ #define TYPEOF_OR_VOIDPTR(type) typeof(type)
+#else
+ #define TYPEOF_OR_VOIDPTR(type) void *
+#endif
+
+/**
+ * Iterate over all nodes in a list.
+ *
+ * This macro generates a "for" statement using the following parameters:
+ * \param n Node pointer to be used in each iteration.
+ * \param l Pointer to list.