I am trying to wrap my head around the concept of using macros to define data structure operations. The following code is a simple example to use the built in list library i
First read this to get a hold what these macros do. And then go to queue.h
. You'll get your treasure trove there!
I found a few gold coins for you-
#define STAILQ_HEAD(name, type) \
struct name { \
struct type *stqh_first;/* first element */ \
struct type **stqh_last;/* addr of last next element */ \
}
Lets dig in a bit deep and answer your questions
What is stailhead? This seems to be "just" defined.
#define STAILQ_HEAD(name, type) \
struct name { \
struct type *stqh_first;/* first element */ \
struct type **stqh_last;/* addr of last next element */ \
}
STAILQ_HEAD(stailhead, entry) head =
STAILQ_HEAD_INITIALIZER(head);
struct stailhead *headp; /* Singly-linked tail queue head. */
So stailhead
is a structure
How to pass head and entries to a function?
#define STAILQ_ENTRY(type) \
struct { \
struct type *stqe_next; /* next element */ \
}
So entries
and head
( as explained before ) are just structures and you can pass them just as you pass other structures. &structure_variable
What type is head, how can I declare a pointer to it?
Already explained!
Read this man page for nice pretty examples.