Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6045845
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T07:10:12+00:00 2026-05-23T07:10:12+00:00

At the moment I am working on creating a small library for common data

  • 0

At the moment I am working on creating a small library for common data structures in C. This is mainly for learning purposes, but I do plan to use this library in other projects to see how well it works and where the problems are. So far I’m content with my hash and binary tree implementation, but I cannot decide on the design of the linked list.

All the data structures implemented so far work with void pointers and take no responsibility for creating or destroying data, i.e. they only reference the data. One design goal is to keep them as generic as possible to increase the reuseability.

Regarding the linked list, I’ve found three approaches so far:

  1. Dedicated list head: the list features a dedicated list head which is used as an abstract data type.

  2. Nodes only: like the example above, except that all functions operate on a list_node. Used in GLib.

  3. In payload: add a list_node structure to the payload data and calculate the offset to the payload with a macro. See lists in the linux kernel

  4. EDIT Generate typed lists with macros: use macros to create type-specific versions of the list structures and functions.

    Example for 1 and 2:


/* list.h */
typedef struct list_t list;

typedef int (*comparator)(const void* a, const void* b);

list* list_new          (comparator c);
void  list_delete       (list* l);
void  list_insert_after (list* l, uint32_t index, void* data);
void  list_remove       (list* l, void* data);
uint32_t list_size      (list* l);
/* other functions operating on lists */

/* list.c */
#include "list.h"

typedef struct list_node_t {
  struct list_node_t* next;
  struct list_node_t* prev;
  void* data;
} list_node;

struct list_t {
  list_node* begin;
  list_node* end;
  uint32_t   size;
  comparator cmp;
}

Now to the question: which of these approaches is the most versatile? Are there any other approaches?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T07:10:12+00:00Added an answer on May 23, 2026 at 7:10 am

    I prefer the second approach, i.e. nodes only.

    It has the advantage of being extremely simple, since the results of most list operations (split, push, pop, sublist, …) are themselves lists.

    Also note that you’re lacking important list operations, mainly push() and pop(). You should make use of the fact that lists allow insertion in O(1).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Alright, this may take a moment or two to explain: I'm working on creating
I'm working my way into MVC at the moment, but on my To learn
I found this in the code I'm working on at the moment and thought
At the moment I am working on a project admin application in C# 3.5
Working on a project at the moment and we have to implement soft deletion
I am working with legacy systems at the moment, and a lot of work
A project I'm working on at the moment involves refactoring a C# Com Object
I'm working on a project were we have number (5 at the moment) of
Ok I'm working on a little project at the moment, the Report expects an
I'm working on a Silverlight control that will allow multi-file downloading. At the moment

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.