[Issue 22839] New: Add equivalent of C 'static' for symbols

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Mar 3 09:18:27 UTC 2022


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

          Issue ID: 22839
           Summary: Add equivalent of C 'static' for symbols
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: dkorpel at live.nl

When translating C code to D, I sometimes come across a static function with a
name that could easily clash if it weren't static:

```
static void terminate() {}
```

The closest equivalent D signature would be:
```
extern(C) private void terminate() {}
```

However, even with `private` the compiler intentionally emits a global
`terminate` symbol to the object file (see Issue 7083). I could mark it
extern(D) so it would get a mangled name that wouldn't clash, but that also
changes the ABI. Considering static symbol support was added to dmd for ImportC
(issue 22428), it might be worth exposing this to D code as well using
something like `@Cstatic` or `pragma(noLinkerSymbol)`.

--


More information about the Digitalmars-d-bugs mailing list