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 @@ -143,6 +143,31 @@ $(H2 $(LNAME2 d-side, ImportC from D's Point of View))
143
143
static assert(E.min == 0 && E.max == 2);
144
144
---
145
145
146
+ $(H2 $(LNAME2 wrapping, Wrapping C Code))
147
+
148
+ $(P Many difficulties with adapting C code to ImportC can be done without
149
+ editing the C code itself. Wrap the C code in another C file and then
150
+ $(CCODE #include) it. Consider the following problematic C file $(TT file.c):)
151
+
152
+ $(CCODE
153
+ void func(int *__restrict p);
154
+ int S;
155
+ struct S { int a, b; };
156
+ )
157
+
158
+ $(P The problems are that $(CCODE __restrict) is not a type qualifier recognized by ImportC
159
+ (or C11),
160
+ and the struct `S` is hidden from D by the declaration $(CCODE int S;).
161
+ To wrap $(TT file.c) with a fix, create the file $(TT file_ic.c) with the contents:)
162
+
163
+ $(CCODE
164
+ #define __restrict restrict
165
+ #include "file.c"
166
+ typedef struct S S_t;
167
+ )
168
+
169
+ $(P Then, `import file_ic;` instead of `import file;`, and use `S_t` when $(CCODE struct S) is desired.)
170
+
146
171
$(H2 $(LNAME2 warnings, Warnings))
147
172
148
173
$(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