Just another update
This commit is contained in:
parent
a25938f123
commit
00a190b0a6
6591 changed files with 94363 additions and 23227 deletions
|
|
@ -1,3 +1,4 @@
|
|||
Show the syntax for a complete stoppage of a program inside a [[Conditional Structures|conditional]]. This includes all [[threads]]/[[processes]] which are part of your program.
|
||||
Show the syntax for a complete stoppage of a program inside a [[Conditional Structures|conditional]].
|
||||
This includes all [[threads]]/[[processes]] which are part of your program.
|
||||
|
||||
Explain the cleanup (or lack thereof) caused by the termination (allocated memory, database connections, open files, object finalizers/destructors, run-on-exit hooks, etc.). Unless otherwise described, no special cleanup outside that provided by the operating system is provided.
|
||||
|
|
|
|||
|
|
@ -1,2 +1,4 @@
|
|||
---
|
||||
category:
|
||||
- Simple
|
||||
note: Basic language learning
|
||||
|
|
|
|||
9
Task/Program-termination/AWK/program-termination-2.awk
Normal file
9
Task/Program-termination/AWK/program-termination-2.awk
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
# usage: awk -f exittest.awk input.txt
|
||||
BEGIN { print "# Exit-Test" }
|
||||
|
||||
#/s.*t/ { print "!", NR, $0; next } #1: List all matches
|
||||
/s.*t/ { print "!", NR, $0; problem=1; exit} #2: Abort after first match
|
||||
{ print " ", NR, $0}
|
||||
|
||||
END { if(problem) {print "!! Problem !!"; exit 2} }
|
||||
END { print "# Lines read:", NR }
|
||||
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;
|
||||
}
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
(if something
|
||||
(kill-emacs))
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
problem=1
|
||||
if (problem) {
|
||||
exit gnuplot
|
||||
}
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
IF problem THEN
|
||||
HALT(1)
|
||||
END
|
||||
|
|
@ -5,7 +5,7 @@ exit
|
|||
|
||||
|
||||
/*─────2nd way────────────────────────────────────────────────────────*/
|
||||
exit (expression) /*Note: the "expression" doen't need parenthesis*/
|
||||
exit (expression) /*Note: the "expression" doesn't need parentheses*/
|
||||
/*"expression" is any REXX expression. */
|
||||
|
||||
|
||||
|
|
@ -16,7 +16,7 @@ return /*which returns to this program's invoker. If */
|
|||
|
||||
|
||||
/*─────4th way────────────────────────────────────────────────────────*/
|
||||
return (expression) /* [See the note above concerning parenthesis.] */
|
||||
return (expression) /* [See the note above concerning parentheses.] */
|
||||
|
||||
|
||||
/*─────5th way────────────────────────────────────────────────────────*/
|
||||
|
|
|
|||
|
|
@ -1,3 +1,8 @@
|
|||
if problem
|
||||
exit(1)
|
||||
exit(1)
|
||||
end
|
||||
|
||||
# or
|
||||
if problem
|
||||
abort # equivalent to exit(1)
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,3 +1,3 @@
|
|||
if problem
|
||||
abort # equivalent to exit(1)
|
||||
exit! # default value 1
|
||||
end
|
||||
|
|
|
|||
6
Task/Program-termination/Scala/program-termination.scala
Normal file
6
Task/Program-termination/Scala/program-termination.scala
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
if (problem) {
|
||||
// sys.exit returns type "Nothing"
|
||||
sys.exit(0)
|
||||
// conventionally, error code 0 is the code for "OK",
|
||||
// while anything else is an actual problem
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue