4 ms·
I wanted to adapt someone's command-line-based program into a library, but it wasn't designed as such. The program was strewn with calls to exit(), and on enco
by dfranke 17y ago
I wanted to adapt someone's command-line-based program into a library, but it wasn't designed as such. The program was strewn with calls to exit(), and on encountering one of these I would just want to return to the function that called into the library rather than exiting the whole program. So I did a setjmp() prior to calling into it, and used the preprocessor to turn exit() into longjmp().
- tome 17y agoI don't get it. Why not just remove the exit() and have the function return to where it was called, as standard?
- parenthesis 17y agoBecause, presumably, the program wasn't written as one big main() function, and at least one of the exit()s wasn't in main() — hence the use of longjmp() to jump out of all the layers of function calls back to the caller of the `library'.