Compare commits

..

2 Commits

Author SHA1 Message Date
e498c821bf show data structure base and link address 2026-01-13 22:41:16 -05:00
f13a774766 some correctness changes 2026-01-13 22:40:55 -05:00
2 changed files with 8 additions and 6 deletions

View File

@@ -1,9 +1,11 @@
#include <stdlib.h>
#include <stdbool.h>
#ifndef __NICKEL_LINKEDLIST_H_ #ifndef __NICKEL_LINKEDLIST_H_
#define __NICKEL_LINKEDLIST_H_ #define __NICKEL_LINKEDLIST_H_
#include <stdlib.h>
#include <stddef.h>
#include <stdint.h>
#include <stdbool.h>
typedef struct ni_list_node { typedef struct ni_list_node {
struct ni_list_node* next; struct ni_list_node* next;
struct ni_list_node* prev; struct ni_list_node* prev;
@@ -46,10 +48,10 @@ static inline ni_list_node* ni_list__get_back(ni_list* l) {
/* Iter Helpers */ /* Iter Helpers */
#define NI_LIST__FOREACH(lptr) \ #define NI_LIST__FOREACH(lptr) \
for (ni_list_node* it = ni_list__get_front(lptr); it != &(lptr)->head; it = it->next) for (ni_list_node* it = (lptr)->head.next; it != &(lptr)->head; it = it->next)
#define NI_LIST_FOREACH_SAFE(tmp, lptr) \ #define NI_LIST_FOREACH_SAFE(tmp, lptr) \
for (ni_list_node* it = ni_list__get_front(lptr), *tmp = it->next; \ for (ni_list_node* it = (lptr)->head.next, *tmp = it->next; \
it != &(lptr)->head; \ it != &(lptr)->head; \
it = tmp, tmp = it-> next) it = tmp, tmp = it-> next)

View File

@@ -50,7 +50,7 @@ int main (void)
size_t test_size = 10; size_t test_size = 10;
for(size_t i = 0; i < test_size; i++) { for(size_t i = 0; i < test_size; i++) {
test_data* t = malloc(sizeof(test_data)); test_data* t = malloc(sizeof(test_data));
printf("n = %d allocated data...link at %p...\n", i, &t->link); printf("n = %d allocated data at %p...test_data.link at %p...\n", i, &t, &t->link);
t->data1 = rand() % UINT64_MAX; t->data1 = rand() % UINT64_MAX;
t->data2 = rand() % UINT64_MAX; t->data2 = rand() % UINT64_MAX;