use C99 flexible array to mark the node's payload

Sun, 07 Feb 2021 21:14:39 +0100

author
Mike Becker <universe@uap-core.de>
date
Sun, 07 Feb 2021 21:14:39 +0100
changeset 403
8fa43b732980
parent 402
a34b93911956
child 404
86ebc3745e62

use C99 flexible array to mark the node's payload

src/linked_list.c file | annotate | diff | comparison | revisions
--- a/src/linked_list.c	Sun Feb 07 21:03:30 2021 +0100
+++ b/src/linked_list.c	Sun Feb 07 21:14:39 2021 +0100
@@ -82,7 +82,7 @@
 struct cx_linked_list_node {
     void *prev;
     void *next;
-    int payload;
+    char payload[];
 };
 
 typedef struct {
@@ -95,7 +95,7 @@
     CxAllocator allocator = list->allocator;
 
     struct cx_linked_list_node *node = cxMalloc(allocator,
-            sizeof(struct cx_linked_list_node) - sizeof(int) + list->itemsize);
+            sizeof(struct cx_linked_list_node) + list->itemsize);
     if (node == NULL)
         return 1;
 

mercurial