www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Rosettacode: program termination

reply "bearophile" <bearophileHUGS lycos.com> writes:
I have added a D entry regarding how to terminate D programs. 
What's missing?

http://rosettacode.org/wiki/Program_termination#D

Bye,
bearophile
Apr 14 2014
parent reply "John Colvin" <john.loughran.colvin gmail.com> writes:
On Monday, 14 April 2014 at 09:58:09 UTC, bearophile wrote:
 I have added a D entry regarding how to terminate D programs. 
 What's missing?

 http://rosettacode.org/wiki/Program_termination#D

 Bye,
 bearophile
I think notInifnite is too contrived, you would always just use `else` there. This is more realistic: int notInfinite(in int b) pure nothrow { if (b < 0) return 10; if (b > 10) return 20; // In release mode this becomes a halt, and it's sometimes // necessary. If you remove this the compiler gives: // Error: function test.notInfinite no return exp; // or assert(0); at end of function assert(false); }
Apr 14 2014
parent reply "bearophile" <bearophileHUGS lycos.com> writes:
John Colvin:

 I think notInifnite is too contrived, you would always just use 
 `else` there. This is more realistic:

 int notInfinite(in int b) pure nothrow {
     if (b < 0)
         return 10;
     if (b > 10)
         return 20;

     // In release mode this becomes a halt, and it's sometimes
     // necessary. If you remove this the compiler gives:
     // Error: function test.notInfinite no return exp;
     //    or assert(0); at end of function
     assert(false);
 }
OK, I have improved the code: http://rosettacode.org/wiki/Program_termination#D Bye, bearophile
Apr 14 2014
parent reply "Andrea Fontana" <nospam example.com> writes:
On Monday, 14 April 2014 at 11:16:41 UTC, bearophile wrote:
 John Colvin:

 I think notInifnite is too contrived, you would always just 
 use `else` there. This is more realistic:

 int notInfinite(in int b) pure nothrow {
    if (b < 0)
        return 10;
    if (b > 10)
        return 20;

    // In release mode this becomes a halt, and it's sometimes
    // necessary. If you remove this the compiler gives:
    // Error: function test.notInfinite no return exp;
    //    or assert(0); at end of function
    assert(false);
 }
OK, I have improved the code: http://rosettacode.org/wiki/Program_termination#D Bye, bearophile
What about: static ~this() { "asdasdasd".writeln; } ?
Apr 15 2014
parent reply "bearophile" <bearophileHUGS lycos.com> writes:
Andrea Fontana:

 What about:

 static ~this() { "asdasdasd".writeln; }
I have added it. Bye, bearophile
Apr 15 2014
parent reply "Andrea Fontana" <nospam example.com> writes:
On Tuesday, 15 April 2014 at 09:30:21 UTC, bearophile wrote:
 Andrea Fontana:

 What about:

 static ~this() { "asdasdasd".writeln; }
I have added it. Bye, bearophile
http://dpaste.dzfl.pl/33cb0a05f0ff Static destructor is called! Application output: spam at exit bar at exit foo at exit Never called
Apr 15 2014
parent reply "bearophile" <bearophileHUGS lycos.com> writes:
Andrea Fontana:

 http://dpaste.dzfl.pl/33cb0a05f0ff

 Static destructor is called!

 Application output:
 spam at exit
 bar at exit
 foo at exit
 Never called
Well, we have a little mystery here :-) Using both the latest beta of ldc2 and the latest alpha of dmd, on Windows32 I don't see "Never called" called :-) Perhaps this incongruence is another little compiler bug? :-) Bye, bearophile
Apr 15 2014
parent reply "Andrea Fontana" <nospam example.com> writes:
On Tuesday, 15 April 2014 at 09:48:57 UTC, bearophile wrote:
 Andrea Fontana:

 http://dpaste.dzfl.pl/33cb0a05f0ff

 Static destructor is called!

 Application output:
 spam at exit
 bar at exit
 foo at exit
 Never called
Well, we have a little mystery here :-) Using both the latest beta of ldc2 and the latest alpha of dmd, on Windows32 I don't see "Never called" called :-) Perhaps this incongruence is another little compiler bug? :-) Bye, bearophile
I think so. On dpaste using 2.063.2 or git version that function isn't called. Only on 2.065.. More: import std.stdio; "Never called".writeln; This doens't work on git version (only in 2.065). I think it is a known behaviour about "local" import + ufcs. Why does it work on 2.065?
Apr 15 2014
parent "bearophile" <bearophileHUGS lycos.com> writes:
Andrea Fontana:

 I think so. On dpaste using 2.063.2 or git version that 
 function isn't called. Only on 2.065..
The C exit() function is not required to honour D module destructors.
 More:
 import std.stdio;
 "Never called".writeln;

 This doens't work on git version (only in 2.065). I think it is 
 a known behaviour about "local" import + ufcs. Why does it work 
 on 2.065?
This code should work (because the imported names are not locally defined), and it correctly works with the latest dmd alpha :-) Bye, bearophile
Apr 15 2014