What exactly are you talking about here? If you do shut down
the program then you do shut it down, that's it. Whether you
do it up the stack in the main() or in the memory allocator
may or may not be different. If it's not different, then it
1) doesn't make much sense to unwind the stack;
2) actually is more expensive to unwind the stack: the more
code the more bugs you got.
Where it's not true, it's not true.
exit() does NOT write buffers not already given into the stream,
save data local to the functions in the call chain,
lots of other work a clean shutdown has to do.
However catching any error (including malloc() fails) is a must.
Right, malloc() result must always be checked. Except it doesn't
imply your code must be cluttered with if() for every call to
whatever_func_you_use_to_allocate_memory().
Ah, you means really that you should never check for error but
shorthand exit() when an fopen() fails, a fread() or fwrite() can't do
its job its asced for? Becausae you code gets cluddered on if on that?
By that my code is full of fuctions designed to use in that program
only once - because these functions are designed to hide details of
work frm the process through the action.
Right, it can. Except it can't draw if it doesn't have
memory to draw. I don't care if the application is still
up if it doesn't display the stuff it's supposed to display.
Nor do I care how it exits on OOM, using abort() or exit(0)
or exit(EXIT_FAILURE); does it exit from main() after everything
properly returned an error or right in the draw_thingie()
call (AFTER it properly cleaned up its crap, how about that?).
There is no need to exit() or abort() a failsave app. You can't draw?
Defere the action until you can do it again. It doesn't matter why you
can't. In some time later you'll be able to do the the job. You can't
show an error to the user? Hi, your log will show that fact.
However only the caller or one of its parents in the chain will know
how to handle the failture "no memory" in a usefull way. There is a
need to unwind the stack until the error can be handled useful. Hey,
only that may give you the needed resources to interact with the user
or other parter your program interacts with.
However when your program comes in a situation where it can't continue
the active action because lack of resorce needed unwind until it is in
the state "nothing done yet" again. Then redo the same thing may end
successfull or fail again. Depending on the current environment there
can be a chance to retry, defere to later or simply shut down clean.
But in any way there is no need to exit() or abort() only because a
resource needed to continue is unavailable yet.
At least it doesn't matter if a job can't success because lack of
resource (menory, handles, atoms, or whatever else), important is that
the app gets back to a state it is able to save anything worth to get
saved before it gets lost.
--
Tschau/Bye
Herbert
Visit
http://www.ecomstation.de the home of german eComStation
eComStation 1.2R Deutsch ist da!