Idris2/tests/chez/chez022/mkalloc.c
2020-06-08 20:46:25 +01:00

28 lines
440 B
C

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
typedef struct {
int val;
char* str;
} Stuff;
Stuff* mkThing() {
static int num = 0;
Stuff* x = malloc(sizeof(Stuff));
x->val = num++;
x->str = malloc(20);
strcpy(x->str,"Hello");
return x;
}
char* getStr(Stuff* x) {
return x->str;
}
void freeThing(Stuff* x) {
printf("Freeing %d %s\n", x->val, x->str);
free(x->str);
free(x);
}