Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
53
Task/Program-termination/D/program-termination-1.d
Normal file
53
Task/Program-termination/D/program-termination-1.d
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
import core.stdc.stdio, core.stdc.stdlib;
|
||||
|
||||
extern(C) void foo() nothrow {
|
||||
"foo at exit".puts;
|
||||
}
|
||||
|
||||
extern(C) void bar() nothrow {
|
||||
"bar at exit".puts;
|
||||
}
|
||||
|
||||
extern(C) void spam() nothrow {
|
||||
"spam at exit".puts;
|
||||
}
|
||||
|
||||
int baz(in int x) pure nothrow
|
||||
in {
|
||||
assert(x != 0);
|
||||
} body {
|
||||
if (x < 0)
|
||||
return 10;
|
||||
if (x > 0)
|
||||
return 20;
|
||||
|
||||
// x can't be 0.
|
||||
|
||||
// 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);
|
||||
}
|
||||
|
||||
// This generates an error, that is not meant to be caught.
|
||||
// Objects are not guaranteed to be finalized.
|
||||
int empty() pure nothrow {
|
||||
throw new Error(null);
|
||||
}
|
||||
|
||||
static ~this() {
|
||||
// This module destructor is never called if
|
||||
// the program calls the exit function.
|
||||
import std.stdio;
|
||||
"Never called".writeln;
|
||||
}
|
||||
|
||||
void main() {
|
||||
atexit(&foo);
|
||||
atexit(&bar);
|
||||
atexit(&spam);
|
||||
|
||||
//abort(); // Also this is allowed. Will not call foo, bar, spam.
|
||||
exit(0);
|
||||
}
|
||||
21
Task/Program-termination/D/program-termination-2.d
Normal file
21
Task/Program-termination/D/program-termination-2.d
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
import core.runtime, std.c.stdlib;
|
||||
|
||||
static ~this() {
|
||||
// This module destructor is called if
|
||||
// the program calls the dexit function.
|
||||
import std.stdio;
|
||||
"Called on dexit".writeln;
|
||||
}
|
||||
|
||||
void dexit(int rc) {
|
||||
// Calling dexit() should have the same effect with regard to cleanup as as reaching the end of the main program.
|
||||
Runtime.terminate();
|
||||
exit(rc);
|
||||
}
|
||||
|
||||
int main() {
|
||||
if(true) {
|
||||
dexit(0);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue