digitalmars.D.learn - D exit() function?
- Jarrett Billingsley (6/6) Mar 25 2007 I'm kind of dumbfounded. I can't find any kind of D-compatible exit()
- Sean Kelly (4/11) Mar 25 2007 It doesn't currently exist. However, "throw new Object" would
- Jarrett Billingsley (4/7) Mar 25 2007 Except that it would print an error message, and exiting without an erro...
- Saaa (1/8) Mar 25 2007 Haha, so I wasn't just too dumb to find it :)
- Krzysztof =?UTF-8?B?U3p1a2llxYJvasSH?= (9/16) Mar 25 2007 I think simple scope(exit) should do the trick.
- Jarrett Billingsley (19/27) Mar 25 2007 No, I'm not looking for an atexit() replacement, sorry. I'm looking for...
- Daniel Keep (15/77) Mar 25 2007 This should be portable, and ensures that all dtors (class and module)
I'm kind of dumbfounded. I can't find any kind of D-compatible exit() function in phobos. Using std.c.stdlib.exit will simply end the program, and module dtors/gc_term won't be called. There's nothing in std.thread either. Am I missing something? Or is this something that should probably be added to phobos?
Mar 25 2007
Jarrett Billingsley wrote:I'm kind of dumbfounded. I can't find any kind of D-compatible exit() function in phobos. Using std.c.stdlib.exit will simply end the program, and module dtors/gc_term won't be called. There's nothing in std.thread either. Am I missing something? Or is this something that should probably be added to phobos?It doesn't currently exist. However, "throw new Object" would accomplish much the same thing. Sean
Mar 25 2007
"Sean Kelly" <sean f4.ca> wrote in message news:eu6fvd$f5r$2 digitalmars.com...It doesn't currently exist. However, "throw new Object" would accomplish much the same thing. SeanExcept that it would print an error message, and exiting without an error is certainly a possible scenario.
Mar 25 2007
Haha, so I wasn't just too dumb to find it :)It doesn't currently exist. However, "throw new Object" would accomplish much the same thing. SeanExcept that it would print an error message, and exiting without an error is certainly a possible scenario.
Mar 25 2007
Jarrett Billingsley wrote:I'm kind of dumbfounded. I can't find any kind of D-compatible exit() function in phobos. Using std.c.stdlib.exit will simply end the program, and module dtors/gc_term won't be called. There's nothing in std.thread either. Am I missing something? Or is this something that should probably be added to phobos?I think simple scope(exit) should do the trick. void exitFun(){ ... } void main(){ scope(exit) exitFun(); ... }
Mar 25 2007
"Krzysztof Szukielojc" <krzysztof.szukielojc gmail.com> wrote in message news:eu6m78$m1r$1 digitalmars.com...I think simple scope(exit) should do the trick. void exitFun(){ ... } void main(){ scope(exit) exitFun(); ... }No, I'm not looking for an atexit() replacement, sorry. I'm looking for a way to end my D program at an arbitrarily deep call depth and still have it call the RTL cleanup functions. I suppose it would be possible to do something like: extern(C) void _cleanupD() { _moduleDtor(); gc_term(); } .. void main() { atexit(&_cleanupD); // program } But that's horribly non-portable. Something like this should be in Phobos.
Mar 25 2007
Jarrett Billingsley wrote:"Krzysztof Szukielojc" <krzysztof.szukielojc gmail.com> wrote in message news:eu6m78$m1r$1 digitalmars.com...Another way of doing it, stolen from Python :PI think simple scope(exit) should do the trick. void exitFun(){ ... } void main(){ scope(exit) exitFun(); ... }No, I'm not looking for an atexit() replacement, sorry. I'm looking for a way to end my D program at an arbitrarily deep call depth and still have it call the RTL cleanup functions. I suppose it would be possible to do something like: extern(C) void _cleanupD() { _moduleDtor(); gc_term(); } ... void main() { atexit(&_cleanupD); // program } But that's horribly non-portable. Something like this should be in Phobos.class SystemExit : Object {} int main(char[][] args) { int result = 0; try { result = appmain(args); } catch( SystemExit e ) { // Meh. } return result; } int appmain(char[][] args) { // Your code here! } // ... void really_deep_function() { throw new SystemExit; }This should be portable, and ensures that all dtors (class and module) and scope(exit)/scope(failure) get executed. It might take a little longer to get back up to main, but at least it should be safe :) -- Daniel -- int getRandomNumber() { return 4; // chosen by fair dice roll. // guaranteed to be random. } http://xkcd.com/ v2sw5+8Yhw5ln4+5pr6OFPma8u6+7Lw4Tm6+7l6+7D i28a2Xs3MSr2e4/6+7t4TNSMb6HTOp5en5g6RAHCP http://hackerkey.com/
Mar 25 2007