lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]



On Thu, Jun 25, 2020 at 11:30 AM Lorenzo Donati <lorenzodonatibz@tiscali.it> wrote:
Yep. Thanks. I did know the existance of those functions. After the the
brief discussion with Francisco Olarte, I wonder whether all those
standard functions to perform exit are really useful.

It seems that exiting an application is quite complicated and requires
custom code that relies both on the os and the specific application.

I wonder how many people really use all this C standard facilities
instead of writing their own exit function.

-- Lorenzo

In general, the "standard" facilities are only useful as an emergency abort -- when your application has entered a state that can't be recovered from, you can use the exit() family of functions to at least try to terminate without making too much of a mess. Things that absolutely must be properly handled even during an emergency abort can then provide an atexit callback. Otherwise, you should always try to end the program by setting things up so that control flow bubbles up to main(), which then returns as normal. (As mentioned, typically this is done by flagging the event loop to stop looping.)

That said, most people don't write their own either. They use one of the countless event handling libraries (glib, libuv, the Windows message pump, etc.) to abstract out the nitty-gritty details.

In C++ you can throw an exception, which will unwind the stack properly on the way out, and if main() doesn't catch it, then it calls abort(). C has no standard equivalent.

/s/ Adam