D Language / DLang 2.100.0 has been officially released. This release contains 22 major changes and 179 fixed Bugzilla issues.
major changes
- Improve C++ header gen
@mustuse
New property that enforces return type error checking- Support for contract invariant version identifiers
- Add .tupleof property to static array
- Zlib updated to 1.2.12
- std.functional introduces a new function bind
- Introducing non-transitive inout returns, and more improvements
Import D code modules in C source using ImportC
As of D 2.099.0, __import
D code modules can be imported directly into C files via keywords.
// dsayhello.d
import core.stdc.stdio : puts;
extern(C) void helloImport() {
puts("Hello __import!");
}
// dhelloimport.c
__import dsayhello;
__import core.stdc.stdio : puts;
int main(int argc, char** argv) {
helloImport();
puts("Cool, eh?");
return 0;
}
Compile with the following code:
dmd dhelloimport.c dsayhello.d
It is also possible to import C code modules that have been compiled with ImportC:
// csayhello.c
__import core.stdc.stdio : puts;
void helloImport() {
puts("Hello _import!");
}
// chelloimport.c
__import csayhello;
__import core.stdc.stdio : puts;
int main(int argc, char** argv) {
helloImport();
puts("Cool, eh?");
return 0;
}
Compile with the following code:
dmd chelloimport.c csayhello.c
Introduce throw expressions
In the life cycle of the D language, it throw
is a statement (statement) and cannot be used in an expression, because the expression must have a type, and since it does not return a value, there is no suitable type, which makes it impossible to use the following syntax. throw
(string err) => throw new Exception(err);
Only the following schemes can be used:
(string err) { throw new Exception(err); }
However, as of D 2.099.0, the following code snippet compiles:
void foo(int function() f) {}
void main() {
foo(() => throw new Exception());
}