[Issue 22031] New: crt

d-bugmail at puremagic.com d-bugmail at puremagic.com
Wed Jun 16 17:20:47 UTC 2021


          Issue ID: 22031
           Summary: crt
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: minor
          Priority: P1
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: mipri at minimaltype.com

This file named imminit.d:

  immutable int example;

  version(D_BetterC) {
      pragma(crt_constructor) extern(C) void initialize() {
          example = 1;
  } else {
      shared static this() {
          example = 1;

Compiles fine without -betterC:

  $ dmd -c imminit.d

And fails with it:

  $ dmd -betterC -c imminit.d
  imminit.d(5): Error: cannot modify `immutable` expression `example`

As https://dlang.org/spec/pragma.html#crtctor states that these functions are
intended as "a simple replacement for shared static this in betterC mode.", it
seems like they should have similar capabilities.


More information about the Digitalmars-d-bugs mailing list