Skip to content

Instantly share code, notes, and snippets.

@DQNEO
Last active December 16, 2015 09:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DQNEO/5413292 to your computer and use it in GitHub Desktop.
Save DQNEO/5413292 to your computer and use it in GitHub Desktop.
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