dmd/changelog/dmd.importc-pragma-stc.dd
Tim Schendekehl 0e8e67097d
Fix bugzilla 23812 - ImportC: allow adding function attributes to imported C functions (#16820)
This adds a new pragma for ImportC, which allows to set default storage
classes. Only `nothrow`, `@nogc` and `pure` are supported for now.
They can be disabled later using `#pragma attribute(pop)`.

Unknown storage classes are ignored.
2024-09-14 10:58:00 -07:00

26 lines
922 B
Text

A pragma for ImportC allows to set `nothrow`, `@nogc` or `pure`
The following new pragma for ImportC allows to set default storage
classes for function declarations:
```
#pragma attribute(push, [storage classes...])
```
The storage classes `nothrow`, `nogc` and `pure` are supported.
Unrecognized attributes are ignored.
Enabling a default storage class affects all function declarations
after the pragma until it is disabled with another pragma.
Declarations in includes are also affected. The following example
enables `@nogc` and `nothrow` for a library:
```
#pragma attribute(push, nogc, nothrow)
#include <somelibrary.h>
```
The changed storage classes are pushed on a stack. The last change can
be undone with the following pragma:
```
#pragma attribute(pop)
```
This can also disable multiple default storage classes at the same time,
if they were enabled with a single `#pragma attribute(push, ...)` directive.