Skip to content

Commit 706ad2d

Browse files
authored
Merge pull request #4321 from Emmankoko/importC
SAOC 25: add importC doc for module decls
2 parents 14f3418 + d70a8ef commit 706ad2d

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
@@ -120,6 +120,33 @@ dmd hello.c)
120120
`.h`, or `.c`, compile `hello` with ImportC.
121121
)
122122

123+
$(P A C file that is imported through a package and gets compiled needs
124+
to have a module declaration that includes that package. It is done by giving it a
125+
label as an importC module using the __module keyword guarded by __IMPORTC__ macro.)
126+
127+
$(P In C file living in project/net/hi.c)
128+
---
129+
#if __IMPORTC__
130+
__module net.hi
131+
#endif
132+
133+
int sqrt(int x) { return x * x; }
134+
---
135+
136+
$(P D file in project/hello.d)
137+
---
138+
import net.hi; // C file you need in your D source
139+
140+
void main()
141+
{
142+
assert(sqrt(3) == 9);
143+
}
144+
---
145+
146+
$(CONSOLE
147+
user@ -- project % dmd hello.d net/hi.c
148+
)
149+
123150
$(H2 $(LNAME2 preprocessor, Preprocessor))
124151

125152
$(P ImportC does not have a preprocessor. It is designed to compile C

0 commit comments

Comments
 (0)