Regarding the terminate handler,
As i understand it, when something bad happens in code, for example when we dont catch an exception,
terminate() is called, which in turn calls abort()
set_terminate(my_function) allows us to get terminate() to call a user specified function my_terminate.
my question is: where do these functions “live” they don’t seem to be a part of the language, but work as if they are present in every single cpp file, without having to include any header file.
If there are default handler functions for
terminateandabortthat you did not install yourself, they’d have to be in the runtime library provided by your compiler.Normally, every program is linked against the runtime library (e.g.
glibcunder Linux). Among other reasons, this is because the runtime library contains “hidden” code for essential things, e.g. code that calls yourmainfunction at startup.