I am currently looking into the use of macros in the C language. To get used to them and to learn I am looking at the queue.h library that allows to create dynamic data structures in C.
You can find the source here: bxr.su/OpenBSD/sys/sys/queue.h
Right now I stumbled upon the following definition:
#define SLIST_ENTRY(type) \
struct { \
struct type *slh_next;
}
If I am not mistaken this creates a struct with a pointer that will point to the next element in the singly-linked list. I just can't figure out, why you have to create the struct. Wouldn't just the pointer be enough?
#define SLIST_ENTRY(type) \
struct type *slh_next
I guess if you want to create a doubly-linked list, you would create a struct with next & before pointers. So is this just to be consistent, or does the struct in the SLIST define serve a specific purpose?
PS: how do I format code and links on mobile?