Created
January 18, 2023 19:56
-
-
Save default-writer/b7ac8addfbf5cc2eacae545deb34cb14 to your computer and use it in GitHub Desktop.
List<T> C implementation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "playground/list/list.h" | |
#include "std/common.h" | |
#define MAX_MEMORY 0xffff // 64K bytes | |
/*private */ | |
// global allocated memory | |
static void** ptr = 0; | |
static void list_init() { | |
ptr = calloc(1, MAX_MEMORY); | |
} | |
static void list_destroy() { | |
free(ptr); | |
ptr = 0; | |
} | |
static void list_push(void* data) { | |
*ptr++ = data; | |
} | |
static void* list_pop() { | |
return *--ptr; | |
} | |
static void* list_peek() { | |
return *(ptr - 1); | |
} | |
/* public */ | |
const struct list list_v1 = { | |
.init = list_init, | |
.destroy = list_destroy, | |
.push = list_push, | |
.pop = list_pop, | |
.peek = list_peek | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment