Started work on floating point compatibility
This commit is contained in:
parent
b2f4a4b8e4
commit
a83400bfdf
12
example.c
12
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));
|
||||
|
||||
|
|
17
ll.h
17
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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue