llwfp

A C library for singly linked lists
Login

A C library for singly linked lists

⇦ previousnext ⇨

Introduction

This is a set of C libraries for handling singly linked lists.

Singly linked list

Quick start

To try out a demo of each library:

    make llwfp-demo
    make llwfp-min-demo

    make ll-int-demo
    make ll-char-p-demo
    make ll-struct-demo
    make ll-array-of-double-demo

Description

llwfp is short for "linked list with function pointers".

Instead of creating one single "one-size-fits-all" library, this is a set of small libraries, where each one may fit different needs.
That has to be said, all libraries have a minimalistic approach.
For more resources and other kind of lists, see the links section.
(Especially, checkout queue.h, the BSD de-facto standard library for linked lists.)

The libraries in this repository can be split into two groups:

  1. Biger source code: Generic node data definition, callbacks to handle data (support for any data type, also mix data types within the same list):

    • llwfp.h: The main library
    • llwfp-min.h: A stripped-down version, basically only 'add' and 'get' functionality
  2. Tiny source code: Simple node data definition, no callbacks, handle data by direct assignment (only support for one single data type):

The second group of libraries may be seen less as "libraries", and more as "templates", to copy-and-paste source code for "quick-and-dirty" solutions, where the smallest possible amount of code is desired, and only one data type has to be considered.

Besides the API documentation, this README also describes how this library was created, step by step (with C examples ).

Debugging tips

As working with linked lists implies lots of calls to malloc(3) and free(3), a memory debugger such as Valgrind is always handy.
As you will see in the source code of llwfp, calloc(3) is used instead of malloc(3).
My experience is that calloc(3) makes Valgrind to complain less.
It may have to do, though, with my lazyness when it comes to initialize memory after calling malloc(3)... ;-)

⇦ previousnext ⇨