Skip to content

Commit aee0c39

Browse files
tim-dlangdlang-bot
authored andcommitted
Document new ImportC pragma for setting attributes
The new pragma is implemented in dlang/dmd#16820. The documentation is based on the changelog entry.
1 parent a5b31d5 commit aee0c39

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

spec/importc.dd

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,33 @@ $(H2 $(LNAME2 preprocessor-directives, Preprocessor Directives))
333333
$(LI $(TT #pragma pack ( pop PopList )))
334334
)
335335

336+
$(H4 $(LNAME2 pragma-attribute, pragma attribute))
337+
338+
The following pragma for ImportC allows to set default storage
339+
classes for function declarations:
340+
---
341+
#pragma attribute(push, [storage classes...])
342+
---
343+
The storage classes `nothrow`, `nogc` and `pure` are supported.
344+
Unrecognized attributes are ignored.
345+
Enabling a default storage class affects all function declarations
346+
after the pragma until it is disabled with another pragma.
347+
Declarations in includes are also affected. The following example
348+
enables `@nogc` and `nothrow` for a library:
349+
350+
---
351+
#pragma attribute(push, nogc, nothrow)
352+
#include <somelibrary.h>
353+
---
354+
355+
The changed storage classes are pushed on a stack. The last change can
356+
be undone with the following pragma:
357+
---
358+
#pragma attribute(pop)
359+
---
360+
This can also disable multiple default storage classes at the same time,
361+
if they were enabled with a single `#pragma attribute(push, ...)` directive.
362+
336363
$(H2 $(LNAME2 _builtins, $(TT src/__builtins.di)))
337364

338365
$(P The first thing the compiler does when preprocessing is complete is to import

0 commit comments

Comments
 (0)