Address arithmetic

Added example for address arithmetic demo using alloc
This commit is contained in:
kdeng00
2021-11-15 21:15:20 -05:00
parent 587504818d
commit cdbd6d2ad1
3 changed files with 100 additions and 0 deletions
+21
View File
@@ -0,0 +1,21 @@
#include "alloc.h"
#include <stdio.h>
char *alloc(int n)
{
if (allocbuf + ALLOCSIZE - allocp >= n) {
allocp += n;
return allocp - n; /* old pointer */
} else {
return 0;
}
}
void afree(char *p)
{
if (p >= allocbuf && p < allocbuf + ALLOCSIZE) {
allocp = p;
}
}