Subject: Re: CIRCLEQ_NEXT/PREV
To: Antti Kantee <firstname.lastname@example.org>
From: SODA Noriyuki <email@example.com>
Date: 12/15/2005 22:52:31
>>>>> On Thu, 15 Dec 2005 15:01:29 +0200, Antti Kantee <firstname.lastname@example.org> said:
> The intended usage of CIRCLEQ_NEXT/PREV goes totally against my intuition,
> as the name implies that I can go around in circles with it.
> It is probably a bit too late to do anything about those macros, but
> I'd like to add two new ones, which actually make me drive in circles:
I think CIRCLEQ should have the following macro at least:
#define CIRCLEQ_IS_END(elm, head) ((elm) == (void *)(head))
> +#define CIRCLEQ_LOOP_NEXT(head, elm, field) \
> + (((elm)->field.cqe_next == (void *)(head)) \
> + ? ((head)->cqh_first) \
> + : (elm->field.cqe_next))
Then you can write the above macro as:
((CIRCLEQ_IS_END(CIRCLEQ_NEXT(elm, field), head)) ?
CIRCLEQ_FIRST(head) : CIRCLEQ_NEXT(elm, field))
And if all list types have similar _IS_END() macro, it becomes to easier
to replace some other list by CIRCLEQ or vice virsa.