Address arithmetic
Added example for address arithmetic demo using alloc
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user