www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 22031] New: crt

https://issues.dlang.org/show_bug.cgi?id=22031

          Issue ID: 22031
           Summary: crt
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: minor
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: mipri 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.

--
Jun 16 2021