Here is the code in C:
#define ALLOCSIZE 1000 /* size of available space */
static char allocbuf[ALLOCSIZE]; /* storage for alloc */
static char *allocp = allocbuf; /* next free position */
char *alloc(int n) /* return pointer to n characters */
{
if (allocbuf + ALLOCSIZE - allocp >= n) { /* it fits */
...
}
}
I don't understand what is happening in the following expression:
allocbuf + ALLOCSIZE - allocp >= n
I know allocbuf as an array name is equivalent to a pointer to the first element &allocbuf[0], and obviously allocp is a pointer, and finally that ALLOCSIZE is a simple int. So adding ALLOCSIZE to allocbuff gives the ALLOCSIZE indexed element of allocbuff which is also a pointer. But subtracting the pointer allocp from pointer &allocbuf[ALLOCSIZE] is where I am lost. I am not even sure one can add pointers in C.
Please tell me where I am wrong or what I am missing in this interpretation.
The point of this program is to store characters.