Re: stdlib.exit()

2012-08-21 Thread Regan Heath
On Mon, 20 Aug 2012 21:03:25 +0100, David wrote: You could define a custom ExitException and throw that, catching it at the top level and returning the error code stored inside it, from main(). Not ideal, but it would work. Thi is really not ideal Didn't I just say that.. :p "Not ideal, b

Re: stdlib.exit()

2012-08-20 Thread Jacob Carlborg
On 2012-08-20 22:04, David wrote: If i interpret it correctly, a call to Runtime.terminate() (as I am doing right now), is the only and correct way? I would think so. -- /Jacob Carlborg

Re: stdlib.exit()

2012-08-20 Thread David
You could define a custom ExitException and throw that, catching it at the top level and returning the error code stored inside it, from main(). Not ideal, but it would work. Thi is really not ideal, since this is for a argument-parser, --help should print the help and then exit.

Re: stdlib.exit()

2012-08-20 Thread David
But why do you want destructors to be called when you call exit()? You are exiting in an "abnormal" way anyway. exit(0) is a normal termination, so destructors should be called. I wanna be nice and deallocate the allocated memory and unload dynamic libraries.

Re: stdlib.exit()

2012-08-20 Thread David
Or the D runtime could just use the "atexit" function defined in stdlib.h. Just add a callback which terminates the D runtime. http://pubs.opengroup.org/onlinepubs/009695299/functions/atexit.html If i interpret it correctly, a call to Runtime.terminate() (as I am doing right now), is the only

Re: stdlib.exit()

2012-08-20 Thread Jacob Carlborg
On 2012-08-20 16:27, bearophile wrote: Regan Heath: You could define a custom ExitException and throw that, catching it at the top level and returning the error code stored inside it, from main(). Not ideal, but it would work. Seems OK. Another solution is to add a dexit() in Phobos :-) Or

Re: stdlib.exit()

2012-08-20 Thread bearophile
Regan Heath: You could define a custom ExitException and throw that, catching it at the top level and returning the error code stored inside it, from main(). Not ideal, but it would work. Seems OK. Another solution is to add a dexit() in Phobos :-) Bye, bearophile

Re: stdlib.exit()

2012-08-20 Thread Regan Heath
On Mon, 20 Aug 2012 10:03:56 +0100, David wrote: Am 20.08.2012 09:15, schrieb Tracey: I use the following: import std.c.stdlib; exit(0); Yeah, but that doesn't terminate the runtime and will not call any dtors, right? std.c.stdlib.exit is the C runtime exit function which doesn't know

Re: stdlib.exit()

2012-08-20 Thread Minas
I don't know about the runtime, but destructors are not called (not sure about module destructors) import std.stdio; import std.c.stdlib; void main() { S s; exit(-1); } struct S { ~this() { writeln("destructor"); } } This prints

Re: stdlib.exit()

2012-08-20 Thread David
Am 20.08.2012 09:15, schrieb Tracey: I use the following: import std.c.stdlib; exit(0); Yeah, but that doesn't terminate the runtime and will not call any dtors, right?

Re: stdlib.exit()

2012-08-20 Thread Tracey
I use the following: import std.c.stdlib; exit(0);

Re: stdlib.exit()

2012-08-19 Thread Minas Mina
On Sunday, 19 August 2012 at 23:48:01 UTC, Minas Mina wrote: That's what I do: import std.c.stdlib; void main(string[] args) { if( args.length == 1 ) { writeln("Some arguments, please!"); exit(-1); } } Sorry, forgot to import std.stdio.

Re: stdlib.exit()

2012-08-19 Thread Minas Mina
That's what I do: import std.c.stdlib; void main(string[] args) { if( args.length == 1 ) { writeln("Some arguments, please!"); exit(-1); } }

stdlib.exit()

2012-08-19 Thread David
I have to "exit" the running program, in C I would call #include exit(0); in Python: sys.exit(0); What's the correct way to do that in D? My current implementation: import core.runtime : Runtime; import core.stdc.stdlib : exit; Runtime.terminate(); exit(0); But that doesn't seem correct.