From a83400bfdf7ee6087434a01480dfe169d0d8cb8b Mon Sep 17 00:00:00 2001 From: Haskell Date: Fri, 4 Oct 2024 08:14:12 +0200 Subject: [PATCH] Started work on floating point compatibility --- example.c | 12 ++++++------ ll.h | 19 ++++++++++--------- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/example.c b/example.c index cefee0a..2b05600 100644 --- a/example.c +++ b/example.c @@ -14,17 +14,17 @@ int main(void) { llList list = llCreateList(); - llAppend(list, 75); + llAppend(list, 75.0f); llAppend(list, 120); llAppend(list, 2377); - llPrepend(list, 665); + llPrepend(list, 665.0f); - int x = llGet(int, list, 0); - printf("x: %d\n", x); + float x = llGet(float, list, 0); + printf("x: %f\n", x); - int * y = llGetRef(int, list, 1); - printf("*y: %d\n", *y); + float * y = llGetRef(float, list, 1); + printf("*y: %f\n", *y); printf("%zu\n", llLen(list)); diff --git a/ll.h b/ll.h index ae6427c..32d2c71 100644 --- a/ll.h +++ b/ll.h @@ -28,13 +28,13 @@ size_t _llGet(llList * list, size_t id); void * _llGetRef(llList * list, size_t id); size_t llLen(llList list); -#define llAppend(list, value) _llAppend(&list, (void *) value) -#define llPrepend(list, value) list = *_llPrepend(&list, (void *) value) -#define llInsert(list, id, value) list = *_llInsert(&list, id, (void *) value) +#define llAppend(list, value) _llAppend(&list, (void *)(uintptr_t) value) +#define llPrepend(list, value) list = *_llPrepend(&list, (void *)(uintptr_t) value) +#define llInsert(list, id, value) list = *_llInsert(&list, id, (void *)(uintptr_t) value) #define llDelete(list, id) list = *_llDelete(&list, id) #define llGet(type, list, id) (type) _llGet(&list, id) -#define llGetRef(type, list, id) (type *) _llGetRef(&list, id) -#define llCreateNode(value) _llCreateNode((void *) value) +#define llGetRef(type, list, id) (type *) (_llGetRef(&list, id)) +#define llCreateNode(value) _llCreateNode((void *)(uintptr_t) value) #ifdef LL_IMPLEMENTATION @@ -152,7 +152,7 @@ llList * _llDelete(llList * list, size_t id) { if (node->next == NULL) { - fprintf(stderr, "RUNTIME ERROR: Index out of bounds\n"); + fprintf(stderr, "ERROR: Index out of bounds\n"); return list; } @@ -176,7 +176,7 @@ size_t _llGet(llList * list, size_t id) { if (node->next == NULL) { - fprintf(stderr, "RUNTIME ERROR: Index out of bounds\n"); + fprintf(stderr, "ERROR: Index out of bounds\n"); llFree(list); exit(1); } @@ -188,6 +188,7 @@ size_t _llGet(llList * list, size_t id) return (size_t) node->data; } +//Todo fix with floating points void * _llGetRef(llList * list, size_t id) { llNode * node = list->nodes; @@ -196,7 +197,7 @@ void * _llGetRef(llList * list, size_t id) { if (node->next == NULL) { - fprintf(stderr, "RUNTIME ERROR: Index out of bounds\n"); + fprintf(stderr, "ERROR: Index out of bounds\n"); return NULL; } @@ -204,7 +205,7 @@ void * _llGetRef(llList * list, size_t id) --id; } - return (void *) &node->data; + return (void *)&node->data; } size_t llLen(llList list)