Hi,,
how to restart (self) application ?
I Need Clean all variable allocateds, and start again the program...
I Know this isn't the best method to a program, but i need urgent..
Hi,,
how to restart (self) application ?
I Need Clean all variable allocateds, and start again the program...
I Know this isn't the best method to a program, but i need urgent..
As I stated earilier (in the other thread - so I guess we should really stop that discussion there), this is non-trivial to do from within your application.
It is not too difficult to reset variables - just write a function that sets all global variables to known values. However, you will not be able to reset the heap, or any states stored inside library functions that you haven't got access to the global/static/heap-allocated variables of, and many other things that you can't "fix up" either.
You need to exit the application and start over again.
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
If you're on a UNIX environment, this isn't too difficult. Get back into the main() function somehow (either returning up to it, or longjmp'ing there), chdir() back to wherever you started (if you moved), close all open file descriptors except for stdin, stdout, stderr, then call:
This also assumes you haven't twiddled anything inside the argv array.Code:execv(argv[0], argv);
Code://try //{ if (a) do { f( b); } while(1); else do { f(!b); } while(1); //}
Yes, works very well [and we could use a setjmp/longjmp pair to get back to main, for example].
Unfortunately I happen to know that the OS that sergioms is using is not unix - it is a DOS-like OS for an embedded microcontroller, and it is sufficiently DOS-like to support Turbo C and Turbo C++, so I guess it performs an "exec()" more like a "spawn()" than Unix exec.
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
thanks a lot again
this topic maybe be closed, matsp helping me in other topic.