The reason it is not possible is that there is a fair amount of shut-down code that executes as soon as main is done. Likewise the memory used by the function and the stack must be deallocated. For that reason, there must be only one exit point in the program: the end of main().
Anonymous
Re: Break en entire program from inside a function.
@Samurai_Crow & Fab: I develop an engine so, if user enter an erroneous value in a function, the program must stop giving the error message in CLI ... so, it's not in this case a bad practise but a need for that precise kind of development.
@DaveP : Thank you for this informations.
All we have to decide is what to do with the time that is given to us.
Using abort() in the Amiga software is not recommended and I would not recommend using exit() either if native API calls are used (windowed applications mostly).
I develop an engine so, if user enter an erroneous value in a function, the program must stop giving the error message in CLI ... so, it's not in this case a bad practise but a need for that precise kind of development.
If you start allocating resources here and there you will find that it is. What's wrong with using return codes ?
Anonymous
Re: Break en entire program from inside a function.
Meanwhile, back on planet do what you fancy. Just use an allocator ADT that automatically deallocates as the registered function on atexit. Or in C++ use smartpointers.
(question to self, does atexit get called... )
Anonymous
Re: Break en entire program from inside a function.
exit() will do this for you, it quits the program exactly as if you'd come to end of main.
Should you require any additional cleanup, ie freeing non Clibrary resources such as amigaos libraries opened by the directly program, memory allocated directly with exec.library then create a cleanup function and pass it to atexit(). It will then be called when you call exit() or when you fall through main().
The only potential problem with atexit() is that there is a limit to the number of functions you can register, the specification specifies at least 32. No ideas what the practical limit for amigaos clibraries is ....
It's always called on exit unless you call abort()
Anonymous
Re: Break en entire program from inside a function.
@Centaurz: In fact you're totally wrong (for my case)
On my system, each plugin has its own constructor() and destructor() function. The engine setup call all constructors and a program end automatically call all destructors and then release all memory/media created for each plugins.
That mean that creating a "break" command for my langage, will result in a command that'll call all destructors and then release all memories :p It's a safe system.
The objective is to create a safe secure exit to prevent crash from when user enter corrupted/erraneour/invalid data in a command of the engine.
Of course the break system will have its own security check to avoid infinite loop if finding error when calling destructors commands ;)
@DaveP : no need ;) @Broadblues : read upper ;)
I think I'm more clear in what I do and why I do that ?
Bye, Fred
Edited by freddix on 2009/7/25 22:04:30
All we have to decide is what to do with the time that is given to us.