Last active
December 16, 2015 09:29
-
-
Save DQNEO/5413292 to your computer and use it in GitHub Desktop.
Address Arithmetic of K&R
This file contains 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 <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