betterC and std.containers don't work together?

Jonathan M Davis newsgroup.d at jmdavisprog.com
Tue Sep 19 05:37:11 UTC 2023


On Monday, September 18, 2023 10:02:00 PM MDT Ki Rill via Digitalmars-d wrote:
> I've been trying out std containers. Checked Phobos code - all
> seems to be @nogc. Good. Then I try out this and it fails because
> something throws in array construction and that's not available
> in betterC: https://run.dlang.io/is/WAjVuG
>
> ```D
> extern(C):
> import core.stdc.stdio;
> import std.container;
>
> void main()
> {
>      printf("hello, world\n");
>      Array!int ai;
>      ai ~= 1;
> }
>
> /* Compiler output:
> /dlang/dmd/linux/bin64/../../src/druntime/import/core/internal/array/constru
> ction.d(207): Error: cannot use try-catch statements with -betterC
> /dlang/dmd/linux/bin64/../../src/phobos/std/container/array.d(151): Error:
> template instance
> `core.internal.array.construction._d_arraysetctor!(const(Array!int)[],
> const(Array!int))` error instantiating
> /dlang/dmd/linux/bin64/../../src/phobos/std/container/array.d(244):
> instantiated from here: `RangeT!(const(Array!int))`
> /dlang/dmd/linux/bin64/../../src/phobos/std/container/array.d(633):
> instantiated from here: `RangeT!(Array!int)` onlineapp.d(8):
> instantiated from here: `Array!int`
> /dlang/dmd/linux/bin64/../../src/druntime/import/core/internal/array/constru
> ction.d(207): Error: cannot use try-catch statements with -betterC
> /dlang/dmd/linux/bin64/../../src/phobos/std/container/array.d(151): Error:
> template instance
> `core.internal.array.construction._d_arraysetctor!(immutable(Array!int)[],
> immutable(Array!int))` error instantiating
> /dlang/dmd/linux/bin64/../../src/phobos/std/container/array.d(639):
> instantiated from here: `RangeT!(immutable(Array!int))` onlineapp.d(8):
>    instantiated from here: `Array!int`
> */
> ```

-betterC is really only intended to make it easier to port C code to D, and
it naturally reduces how much of D that you can use, because it involves not
using D's runtime.

On the other hand, Phobos in general has been designed with the idea that
you will be using the entire language. Some parts of it happen to work with
-betterC, but pretty much all of it was written before -betterC was even a
thing, so if it works with -betterC, it's basically by accident.

- Jonathan M Davis





More information about the Digitalmars-d mailing list