Skip to content

Instantly share code, notes, and snippets.

@DQNEO DQNEO/alloc_afree.c
Last active Dec 16, 2015

Embed
What would you like to do?
Address Arithmetic of K&R
#include <stdio.h>
#include <string.h>
#define ALLOCSIZE 10000
static char allocbuf[ALLOCSIZE];
static char *allocp = allocbuf;
char *alloc(int n)
{
if (allocbuf + ALLOCSIZE - allocp < n) {
return 0;
}
char *oldp = allocp;
allocp += n;
return oldp;
}
void afree(char *p)
{
if (allocbuf <= p && p < allocbuf + ALLOCSIZE) {
allocp = p;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.