Is betterC affect to compile time?

Mike Franklin slavo5150 at yahoo.com
Thu Jul 25 12:20:04 UTC 2019


On Thursday, 25 July 2019 at 12:01:40 UTC, Oleg B wrote:
> Hello everyone!
>
> I try build this code with betterC
>
> import core.stdc.stdio;
> import std.format : format;
>
> extern(C) int main()
> {
>     mixin(format!`enum str = "%s\0";`("hello"));
>     fprintf(stderr, "%s\n", str.ptr);
>     return 0;
> }
>
> but compilation fails
>
> /dlang/dmd/linux/bin64/../../src/phobos/std/format.d(6278): 
> Error: Cannot use try-catch statements with -betterC
> /dlang/dmd/linux/bin64/../../src/phobos/std/format.d(6308): 
> Error: template instance 
> `std.format.checkFormatException!("enum str = \"%s\\0\";", 
> string)` error instantiating
> onlineapp.d(6):        instantiated from here: format!("enum 
> str = \"%s\\0\";", string)
> /dlang/dmd/linux/bin64/../../src/phobos/std/format.d(6311):
>  while evaluating: static assert(!e)
> /dlang/dmd/linux/bin64/../../src/phobos/std/array.d(3204): 
> Error: TypeInfo cannot be used with -betterC
>
> Is this a bug?
>
> https://run.dlang.io/is/TG1uhg

If you read the documentation for betterC 
(https://dlang.org/spec/betterc.html#consequences) you'll see 
that there are features of the D language which are not 
supported. Therefore, libraries that use such features (e.g. 
std.format, std.array) are also not supported, and that is why 
you are encountering such errors.

There are some features of Phobos which can be used in betterC 
builds, but you're going to find that it's hit-and-miss.

Mike


More information about the Digitalmars-d-learn mailing list