@@ -4,7 +4,166 @@ $(SPEC_S ImportC,
4
4
5
5
$(HEADERNAV_TOC)
6
6
7
- $(P Documentation for ImportC coming soon!)
7
+ $(NOTE: This document is a work in progress.)
8
+
9
+ $(P ImportC is a C compiler embedded into the D implementation.
10
+ Its purpose is to enable direct importation of C files, without
11
+ needing to manually prepare a D file corresponding to the the declarations
12
+ in the C file. It enables directly compiling C files into modules, and
13
+ linking them in with D code to form an executable. It can be used
14
+ as a C compiler to compile and link 100% C programs.
15
+ )
16
+
17
+ $(P This is not a C reference manual nor programming tutorial.
18
+ It describes the specifics of the dialect of C that
19
+ ImportC is, and how to use it effectively.)
20
+
21
+
22
+ $(H2 $(LNAME2 dialect, ImportC Dialect))
23
+
24
+ $(P There are many versions of C. ImportC is designed to be an
25
+ implementation of (LINK2 https://en.wikipedia.org/wiki/C11_(C_standard_revision), ISO/IEC 9899:1999),
26
+ which will hereafter be referred to as $(B C11).
27
+ References to the C11 Standard will be C11 followed by the paragraph number.
28
+ Prior versions, such as C99, C89, and K+R C, are not supported.
29
+ )
30
+
31
+ $(P Adjustment to the ImportC dialect is made to match the
32
+ behavior of the C compiler that the D compiler is matched to. For
33
+ example, on Win32 D is matched to the Digital Mars C compiler,
34
+ and can be matched to the Visual C compiler using the $(TT -mscoff32)
35
+ switch. Win64 D is matched to the Visual C compiler.
36
+ On Posix targets, the matching C compiler is Gnu C or Clang C.
37
+ )
38
+
39
+ $(P Further adjustment is made to take advantage of some of the D
40
+ implementation's capabilities.)
41
+
42
+ $(P This is all covered in the rest of this document.)
43
+
44
+
45
+ $(H2 $(LNAME2 command-line, Invoking ImportC))
46
+
47
+ $(P The ImportC compiler can be invoked in two ways:)
48
+
49
+ $(UL
50
+ $(LI directly via the command line)
51
+ $(LI indirectly via importing a C file)
52
+ )
53
+
54
+ $(H3 ImportC Files on the Command Line)
55
+
56
+ $(H3 Importing C Files)
57
+
58
+
59
+ $(H2 $(LNAME2 preprocessor, Preprocessor))
60
+
61
+ $(P ImportC does not have a preprocessor. It is designed to compile C
62
+ files after they have been first run through the C preprocessor.)
63
+
64
+ $(H3 Digital Mars C Preprocessor)
65
+
66
+ $(H3 Gnu C Preprocessor)
67
+
68
+ $(H3 Clang C Preprocessor)
69
+
70
+ $(H3 Warp C Preprocessor)
71
+
72
+
73
+ $(H2 $(LNAME2 preprocessor-directives, Preprocessor Directives))
74
+
75
+ $(P Nevertheless, ImportC supports these preprocessor directives:)
76
+
77
+ $(H3 Line control)
78
+
79
+ $(P C11 6.10.4)
80
+
81
+ $(H3 Linemarker)
82
+
83
+ $(P $(LINK2 https://gcc.gnu.org/onlinedocs/gcc-11.1.0/cpp/Preprocessor-Output.html, linemarker)
84
+ directives are normally embedded in the output of C preprocessors.)
85
+
86
+ $(H2 $(LINK2 limitations, Limitations))
87
+
88
+ $(H3 Exception Handling)
89
+
90
+ $(P ImportC is assumed to never throw exceptions. `setjmp` and `longjmp` are not supported.)
91
+
92
+ $(H3 Transitive Const)
93
+
94
+ $(P C11 specifies that `const` only applies locally. `const` in ImportC applies transitively,
95
+ meaning that although $(CCODE int *const p;) means in C11 that p is a const pointer to int,
96
+ in ImportC it means p is a const pointer to a const int.)
97
+
98
+ $(H2 $(LINK2 extensions, Extensions))
99
+
100
+
101
+ $(H2 $(LINK2 gnu-clang-extensions, Gnu and Clang Extensions))
102
+
103
+
104
+ $(H2 $(LINK2 visualc-extensions, Visual C Extensions))
105
+
106
+
107
+ $(H2 $(LINK2 digital-mars-extensions, Digital Mars C Extensions))
108
+
109
+
110
+ $(H2 $(LINK2 d-side, ImportC from D's Point of View))
111
+
112
+ $(P There is no one-to-one mapping of C constructs to D constructs, although
113
+ it is very close. What follows is a description of how the D side views
114
+ the C declarations that are imported.)
115
+
116
+ $(H3 Module Name)
117
+
118
+ $(P The module name assigned to the ImportC file is the filename stripped
119
+ of its path and extension. This is just like the default module name assigned
120
+ to a D module that does not have a module declaration.)
121
+
122
+ $(H3 `extern (C)`)
123
+
124
+ $(P All C symbols are `extern (C)`.)
125
+
126
+ $(H3 Enums)
127
+
128
+ $(P The C enum:)
129
+
130
+ $(CCODE enum E { A, B = 2 };)
131
+
132
+ $(P appears to D code as:)
133
+
134
+ ---
135
+ enum E : int { A, B = 2 }
136
+ alias A = E.A;
137
+ alias B = E.B;
138
+ ---
139
+
140
+ $(P The `.min` and `.max` properties are available:)
141
+
142
+ ---
143
+ static assert(E.min == 0 && E.max == 2);
144
+ ---
145
+
146
+ $(H2 $(LINK2 warnings, Warnings))
147
+
148
+ $(P Many suspicious C constructs normally cause warnings to be emitted by default by
149
+ typical compilers, such as:)
150
+
151
+ $(CCODE int *p = 3; // Warning: integer implicitly converted to pointer)
152
+
153
+ $(P ImportC does not emit warnings. The presumption is the user will be importing existing C
154
+ code developed using another C compiler, and it is written as intended.
155
+ If C11 says it is legal, ImportC accepts it.)
156
+
157
+ $(H2 $(LINK2 importcpp, ImportC++))
158
+
159
+ $(P ImportC will not compile C++ code. For that, use ($TT dpp).)
160
+
161
+ $(H2 $(LINK2 history, How ImportC Came About))
162
+
163
+ $(H2 $(LINK2 internals, How ImportC Works))
164
+
165
+ $(P This is a description of how ImportC is implemented, intended
166
+ to remove the mystery of various design choices.)
8
167
9
168
$(SPEC_SUBNAV_PREV_NEXT betterc, Better C, ob, Live Functions)
10
169
)
0 commit comments