Requirement is to write some D code (which avoids the GC), that will be called from C.
So simple approach seemed to be to write D code under -betterC restrictions.
However, also need variable length arrays - but D Dynamic Arrays not allowed under -betterC.
So tried trivial example using std.container:
extern(C) void main() {
import std.container;
auto arr = Array!int(0, 2, 3);
}
compiled with:
dmd -betterC -run Array_ex_01v00
Which failed with:
C:\D\dmd2\windows\bin\..\..\src\druntime\import\core\internal\array\construction.d(207): Error: cannot use try-catch statements with -betterC
C:\D\dmd2\windows\bin\..\..\src\phobos\std\container\array.d(151): Error: template instance `core.internal.array.construction._d_arraysetctor!(const(Array!int)[], const(Array!int))` error instantiating
C:\D\dmd2\windows\bin\..\..\src\phobos\std\container\array.d(244): instantiated from here: `RangeT!(const(Array!int))`
C:\D\dmd2\windows\bin\..\..\src\phobos\std\container\array.d(633): instantiated from here: `RangeT!(Array!int)`
Array_ex_01v00.d(5): instantiated from here: `Array!int`
C:\D\dmd2\windows\bin\..\..\src\druntime\import\core\internal\array\construction.d(207): Error: cannot use try-catch statements with -betterC
C:\D\dmd2\windows\bin\..\..\src\phobos\std\container\array.d(151): Error: template instance `core.internal.array.construction._d_arraysetctor!(immutable(Array!int)[], immutable(Array!int))` error instantiating
C:\D\dmd2\windows\bin\..\..\src\phobos\std\container\array.d(639): instantiated from here: `RangeT!(immutable(Array!int))`
Array_ex_01v00.d(5): instantiated from here: `Array!int`
Any ideas how to implement variable length arrays under -betterC?