cdbd6d2ad1
Added example for address arithmetic demo using alloc
22 lines
317 B
C
22 lines
317 B
C
#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;
|
|
}
|
|
}
|