@@ -26,16 +26,14 @@ $(H2 $(LNAME2 examples, Quick Examples))
26
26
{
27
27
printf("hello world\n");
28
28
return 0;
29
- }
30
- )
29
+ })
31
30
32
31
$(P Compile and run:)
33
32
34
33
$(CONSOLE
35
34
dmd hello.c
36
35
./hello
37
- hello world
38
- )
36
+ hello world)
39
37
40
38
$(P C function in file $(TT functions.c):)
41
39
@@ -391,6 +389,41 @@ $(H2 $(LNAME2 limitations, Limitations))
391
389
392
390
$(P $(I Compatible Types) (C11 6.7.2) are identical types in ImportC.)
393
391
392
+
393
+ $(H2 $(LNAME2 impedance-mismatch, Impedance Mismatch))
394
+
395
+ $(P While every effort is made to match up C and D so it "just works", the languages have some
396
+ fundamental differences that appear now and then.
397
+ )
398
+
399
+ $(H3 $(LNAME2 keyword-mismatch, Keyword Mismatch))
400
+
401
+ $(P D and C use mostly the same keywords, C has keywords that D doesn't have, and vice versa. This
402
+ does not affect compilation of C code, but it can cause difficulty when accessing C variables and types
403
+ from D. For example, the D `version` keyword is not uncommonly used as a struct member in C:)
404
+
405
+ $(P C code in file $(TT defs.c):)
406
+ $(CCODE
407
+ struct S { int version; };)
408
+
409
+ $(P Accessing it from D:)
410
+ ---
411
+ import defs;
412
+ int tech(S* s) {
413
+ return s.version; // fails because version is a D keyword
414
+ }
415
+ ---
416
+
417
+ $(P A workaround is available:)
418
+ ---
419
+ import defs;
420
+ int tech(S* s) {
421
+ return __traits(getMember, *s, "version");
422
+ }
423
+ ---
424
+
425
+
426
+
394
427
$(H3 $(LNAME2 same_only_different, Same only Different Types))
395
428
396
429
$(P On some platforms, C `long` and `unsigned long` are the same size as `int` and `unsigned int`, respectively.
0 commit comments