I'm reading through the book C++ reference by Herbert Schildt and there is a stack example in the c section of the book similar to the following:

```
#include <stdio.h>
#include <stdlib.h>

#define SIZE 50

void push(int i);
int pop(void);

int *tos, *p, stack[SIZE];

int main(void) {
    tos = stack;
    p = stack;
    // push, pop, etc
    return 0;
}
void push(int i) {
    p++;
    if (p==(tos+SIZE)) {
        printf("Stack overflow");
        exit(1);
    }
    *p = i; 
}
int pop(void) {
    if (p==tos) {
        printf("Stack Underflow");
        exit(1);
    }
    p--;
    return *(p+1);
}

```

The above stack implementation does not use the TOS for storing a value. The first value is stored at TOS+1. I couldn't see why you would do that as it seems to waste a memory space. 

I have rewritten it to the example below, which doesn't waste the space (EDIT: read the selected answer - the code below is suspect!):

```
#include <stdio.h>
#include <stdlib.h>

#define SIZE 5

void push(int i);
int pop(void);

int *tos, *p, stack[SIZE];

int main(void) {
    tos = stack;
    p = stack;
    // push, pop, etc
    return 0;
}
void push(int i) {
    if (p==(tos+SIZE)) {
        printf("Stack overflow");
        exit(1);
    }
    *p = i; 
    p++;
}
int pop(void) {
    p--;
    if (p<tos) {
        printf("Stack Underflow");
        exit(1);
    }
    return *p;
}

```

Is there a reason for Schildt's implementation not using the TOS position?

Many thanks.