source: doc/generic_types/evaluation/c-stack.c @ 115a868

ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsdeferred_resndemanglerenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumresolv-newwith_gc
Last change on this file since 115a868 was 309be81, checked in by Aaron Moss <a3moss@…>, 7 years ago

Started evaluation benchmarks for paper (CFA version doesn't compile yet)

  • Property mode set to 100644
File size: 725 bytes
Line 
1#include <stdlib.h>
2#include "c-stack.h"
3
4struct stack_node {
5        void* value;
6        struct stack_node* next;
7};
8
9struct stack new_stack() {
10        return (struct stack){ NULL };
11}
12
13void clear_stack(struct stack* s) {
14        struct stack_node* next = s->head;
15        while ( next ) {
16                struct stack_node* crnt = next;
17                next = crnt->next;
18                free(crnt->value);
19                free(crnt);
20        }
21}
22
23_Bool stack_empty(const struct stack* s) {
24        return s->head == NULL;
25}
26
27void push_stack(struct stack* s, void* value) {
28        struct stack_node* n = malloc(sizeof(struct stack_node));
29        *n = (struct stack_node){ value, s->head };
30        s->head = n;
31}
32
33void* pop_stack(struct stack* s) {
34        struct stack_node* n = s->head;
35        s->head = n->next;
36        void* x = n->value;
37        free(n);
38        return x;
39}
Note: See TracBrowser for help on using the repository browser.