File tree Expand file tree Collapse file tree 1 file changed +25
-0
lines changed Expand file tree Collapse file tree 1 file changed +25
-0
lines changed Original file line number Diff line number Diff line change @@ -170,6 +170,31 @@ $(H2 $(LNAME2 d-side, ImportC from D's Point of View))
170
170
static assert(E.min == 0 && E.max == 2);
171
171
---
172
172
173
+ $(H2 $(LNAME2 wrapping, Wrapping C Code))
174
+
175
+ $(P Many difficulties with adapting C code to ImportC can be done without
176
+ editing the C code itself. Wrap the C code in another C file and then
177
+ $(CCODE #include) it. Consider the following problematic C file $(TT file.c):)
178
+
179
+ $(CCODE
180
+ void func(int *__restrict p);
181
+ int S;
182
+ struct S { int a, b; };
183
+ )
184
+
185
+ $(P The problems are that $(CCODE __restrict) is not a type qualifier recognized by ImportC
186
+ (or C11),
187
+ and the struct `S` is hidden from D by the declaration $(CCODE int S;).
188
+ To wrap $(TT file.c) with a fix, create the file $(TT file_ic.c) with the contents:)
189
+
190
+ $(CCODE
191
+ #define __restrict restrict
192
+ #include "file.c"
193
+ typedef struct S S_t;
194
+ )
195
+
196
+ $(P Then, `import file_ic;` instead of `import file;`, and use `S_t` when $(CCODE struct S) is desired.)
197
+
173
198
$(H2 $(LNAME2 warnings, Warnings))
174
199
175
200
$(P Many suspicious C constructs normally cause warnings to be emitted by default by
You can’t perform that action at this time.
0 commit comments