lua-users home
lua-l archive

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


On 24/06/2020 23:00, Sean Conner wrote:
It was thus said that the Great Lorenzo Donati once stated:

However I thought C's `exit` was the right way to exit a program
(possibly together with `atexit` mechanism) if returning from main is
too cumbersome.

  In C89, you have exit().  In C99, you have exit() and _Exit().  In C11,
you have exit(), _Exit() and quick_exit().  Here's what each does.

	exit()

		Run each function registered by atexit() in reverser order
		of registration (at least 32 such functions are supported).

		Write buffered data in open files, and close all open files.
		All files created with tmpfile() are removed.

		Return the status code to the operating system.

	_Exit()

		Return the status code to the operating sytem.

	quick_exit()

		Run each function registered by at_quick_exit() in reverse
		order of registration (at least 32 such functions are
		supported).

		Return the status code to the operating system.

  _Exit() does the least amount of work, exit() the most.  The only
resources that are cleaned up by the C standard library are files (and only
in the case of exit()); memory is not mentioned at all, and in my
experience, on non-virtual memory systems (like MS-DOS or AmigaOS 1.x) this
means it is leaked.

  Also, calling exit() is the same a doing a return from main---that is,
when you return from main, the process is as if you called exit().

  Why one would call quick_exit() or _Exit() is highly dependent upon the
operating system and nature of the program.

  -spc

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