It sort of depends on the use - you could have a "success/fail" return value (e.g. return 0 for succes, -1 for fail, or 1 for success, 0 for fail, depending on your "taste" in return values). This approach moves the problem on to the next level up to check for the error and know what to do. Make sure you use a consistent method for returning "ok" vs. "failed", so that you don't have to "remember" which function returns negative for fail, and which returns 0 for fail and which returns a positive error code for fail... Consistency is important here.
Alternatively, you just "kill the app" by something like
Code:
fprintf(stderr, "Error, stack overflow, got %d elements, max is %d elements", item_count, max_size+1);
exit(1);
In this case, the calling code has no choice in the matter, and no say in how to deal with the error.
A third option would be to realloc the stack array (until that fails, and then panic) - which is OK if you have other checks to detect for example infinitely recursive calls to push() - otherwise you may be waiting quite some time before the stack fills the entire machines memory....
To do appropriate error handling method is very dependant on what you are using the functions for, and what the likelyhood of failing is - if you have a situation where you DON'T EVER expect the stack to run out, and if it does, something else is most likely very wrong anyways, exiting is probably OK. If, on the other hand, you are dealing with user-input that may not be saved by the time your push function is called, and it's entirely possible (if not entirely LIKELY or correct) that the user inputs some expression that leads to the stack overflowing, the second approach should most likely be applied.
--
Mats