Thread overview
how to terminate a program
Oct 25, 2008
james
Oct 25, 2008
dsimcha
Oct 25, 2008
james
Sep 15, 2019
Murilo
Sep 15, 2019
Jonathan M Davis
Sep 15, 2019
Murilo
Re: how to terminate a program - exit(), destructors and issue 19978
Sep 16, 2019
FeepingCreature
Sep 17, 2019
Jonathan M Davis
October 25, 2008
how to terminate the program in the middle of execution, is there any command such as halt,exit? since i dont use exception for error handling.
October 25, 2008
== Quote from james (james@google.com)'s article
> how to terminate the program in the middle of execution, is there any command
such as halt,exit? since i dont use exception for error handling.

Use C's.  It's in std.c.stdlib.  It's called exit, takes an int and returns the exit code provided by the caller to the OS upon termination.
October 25, 2008
dsimcha Wrote:

> == Quote from james (james@google.com)'s article
> > how to terminate the program in the middle of execution, is there any command
> such as halt,exit? since i dont use exception for error handling.
> 
> Use C's.  It's in std.c.stdlib.  It's called exit, takes an int and returns the exit code provided by the caller to the OS upon termination.

thank you very much. it works.
September 15, 2019
On Saturday, 25 October 2008 at 01:41:09 UTC, dsimcha wrote:
> == Quote from james (james@google.com)'s article
>> how to terminate the program in the middle of execution, is there any command
> such as halt,exit? since i dont use exception for error handling.
>
> Use C's.  It's in std.c.stdlib.  It's called exit, takes an int and returns the exit code provided by the caller to the OS upon termination.

Hi, I am trying it but my compiler does not find the std.c.stdlib module. I am using one of the latest versions. Has it been removed?
September 14, 2019
On Saturday, September 14, 2019 9:37:37 PM MDT Murilo via Digitalmars-d wrote:
> On Saturday, 25 October 2008 at 01:41:09 UTC, dsimcha wrote:
> > == Quote from james (james@google.com)'s article
> >
> >> how to terminate the program in the middle of execution, is there any command
> >
> > such as halt,exit? since i dont use exception for error handling.
> >
> > Use C's.  It's in std.c.stdlib.  It's called exit, takes an int and returns the exit code provided by the caller to the OS upon termination.
>
> Hi, I am trying it but my compiler does not find the std.c.stdlib module. I am using one of the latest versions. Has it been removed?

You're replying to a post that's nearly 11 years old. The C bindings were moved to druntime quite some time ago. The bindings for C's standard library are in the package core.stdc. So, the bindings for C's stdlib header are in core.stdc.stdlib.

- Jonathan M Davis



September 15, 2019
> You're replying to a post that's nearly 11 years old. The C bindings were moved to druntime quite some time ago. The bindings for C's standard library are in the package core.stdc. So, the bindings for C's stdlib header are in core.stdc.stdlib.
>
> - Jonathan M Davis

Thanks man. Importing core.stdc.stdlib really worked. :)
September 16, 2019
On Sunday, 15 September 2019 at 03:54:01 UTC, Jonathan M Davis wrote:
> On Saturday, September 14, 2019 9:37:37 PM MDT Murilo via Digitalmars-d wrote:
>>
>> Hi, I am trying it but my compiler does not find the std.c.stdlib module. I am using one of the latest versions. Has it been removed?
>
> You're replying to a post that's nearly 11 years old. The C bindings were moved to druntime quite some time ago. The bindings for C's standard library are in the package core.stdc. So, the bindings for C's stdlib header are in core.stdc.stdlib.
>
> - Jonathan M Davis

Gonna take this opportunity to bring up two related concerns.

First: when you exit the program via exit(), module destructors will not be run. As a result, any modules that rely on this, such as database drivers that close file handles, flush caches to disk, etc. will not get a chance to react.

On the other hand, you will also sidestep issue 19978 which notes that sometimes, D programs (with daemon threads) just randomly crash on exit and nobody knows why.

So you know, you win some, you lose some. :-)
September 17, 2019
On Monday, September 16, 2019 1:24:02 AM MDT FeepingCreature via Digitalmars-d wrote:
> On Sunday, 15 September 2019 at 03:54:01 UTC, Jonathan M Davis
>
> wrote:
> > On Saturday, September 14, 2019 9:37:37 PM MDT Murilo via
> >
> > Digitalmars-d wrote:
> >> Hi, I am trying it but my compiler does not find the std.c.stdlib module. I am using one of the latest versions. Has it been removed?
> >
> > You're replying to a post that's nearly 11 years old. The C bindings were moved to druntime quite some time ago. The bindings for C's standard library are in the package core.stdc. So, the bindings for C's stdlib header are in core.stdc.stdlib.
> >
> > - Jonathan M Davis
>
> Gonna take this opportunity to bring up two related concerns.
>
> First: when you exit the program via exit(), module destructors will not be run. As a result, any modules that rely on this, such as database drivers that close file handles, flush caches to disk, etc. will not get a chance to react.
>
> On the other hand, you will also sidestep issue 19978 which notes that sometimes, D programs (with daemon threads) just randomly crash on exit and nobody knows why.
>
> So you know, you win some, you lose some. :-)

Calling exit is akin to just shooting your process in the head.

- Jonathan M Davis