[Issue 23812] New: ImportC: allow adding function attributes to imported C functions
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Tue Mar 28 13:54:19 UTC 2023
https://issues.dlang.org/show_bug.cgi?id=23812
Issue ID: 23812
Summary: ImportC: allow adding function attributes to imported
C functions
Product: D
Version: D2
Hardware: All
OS: All
Status: NEW
Keywords: ImportC
Severity: enhancement
Priority: P1
Component: dmd
Assignee: nobody at puremagic.com
Reporter: dkorpel at live.nl
C functions imported with ImportC currently don't get any function attributes,
so they're currently not callable in `nothrow` `@nogc` `pure` `@safe` contexts.
nothrow and @nogc could be given by default, the only exceptions would be if
the imported function has a callback, or if it is actually implemented in D but
imported through a C file for some reason.
@safe is rarer for C functions since they often receive raw pointers, so we
might just require use of `@trusted` when calling them from a `@safe` context.
pure is also rarer for C, since C libraries often use global variables / stderr
for error reporting, but ImportC could recognize the `__attribute__((pure))`
extension some compilers have.
In any case, new syntax could be created along the lines of:
```C
#pragma nogc nothrow
#include <somelibrary.h>
```
--
More information about the Digitalmars-d-bugs
mailing list