[cs631apue] Data structure implementations in <sys/queue.h>

Jan Schaumann jschauma at stevens.edu
Tue Sep 4 22:52:19 EDT 2018

Benjamin A Iofel <biofel at stevens.edu> wrote:
> On Mon, Sep 3, 2018 at 10:42 PM, Jan Schaumann <jschauma at stevens.edu<mailto:jschauma at stevens.edu>> wrote:

>> By not including a pointer to the object, and instead requiring the
>> object to contain the list head struct, you also yield branchless
>> insertion/deletion in the list: any object can dereference the next
>> item in the list without having to check the reference on the object.
> How is it branchless? You still have to check whether the next pointer
> is null.

I meant the implementation doesn't need to special case manipulation of
the head (although the man page notes that using the head-specific macro
is going to be more efficient).  However, that may really make more of a
difference in the context of doubly linked lists, as explained here:

I'd guess that keeping the slist and list implementations close to each
other was another design decision made in this interface.


More information about the cs631apue mailing list