diff --git a/spec/betterc.dd b/spec/betterc.dd index 85d5b13fcb..ef7cd62ae0 100644 --- a/spec/betterc.dd +++ b/spec/betterc.dd @@ -63,7 +63,7 @@ Hello betterC be tricky, hence removing D's GC from the equation may be worthwhile sometimes.) ) - $(P BetterC and $(LINK2 https://dlang.org/spec/importc.html) are very different. + $(P BetterC and $(LINK2 https://dlang.org/spec/importc.html, ImportC) are very different. ImportC is an actual C compiler. BetterC is a subset of D that relies only on the existence of the C Standard library.) diff --git a/spec/importc.dd b/spec/importc.dd index d55c0cac33..c50143970b 100644 --- a/spec/importc.dd +++ b/spec/importc.dd @@ -18,7 +18,7 @@ $(HEADERNAV_TOC) It describes the specifics of the dialect of C that ImportC is, and how to use it effectively.) - $(P ImportC and $(LINK2 https://dlang.org/spec/betterc.html) are very different. + $(P ImportC and $(LINK2 https://dlang.org/spec/betterc.html, BetterC) are very different. ImportC is an actual C compiler. BetterC is a subset of D that relies only on the existence of the C Standard library.) @@ -300,8 +300,21 @@ $(H2 $(LNAME2 other-solutions, Other Solutions)) $(H2 $(LNAME2 internals, How ImportC Works)) - $(P This is a description of how ImportC is implemented, intended - to remove the mystery of various design choices.) + $(P ImportC's implementation is based on the idea that D's semantics are very similar + to C's. ImportC gets its own parser, which converts the C syntax into the same AST + (Abstract Syntax Tree) that D uses. The lexer for ImportC is the same as for D, but with + some modifications here and there, such as the keywords and integer literals being different. + Where the semantics of C differ from D, there are adjustments in the semantic analysis + code in the D compiler.) + + $(P This co-opting of the D semantic implementation allows ImportC to be able to do things + like handle forward references, CTFE (Compile Time Function Execution), and inlining of C functions + into D code. Being able to handle forward references means it is not necessary to even + write a .h file to be able to import C declarations into D. Being able to perform CTFE is + very handy for testing that ImportC is working without needing to generate an executable. + But, in general, the strong temptation to add D features to ImportC has been resisted.) + + $(P The optimizer and code generator are, of course, the same as D uses.) $(SPEC_SUBNAV_PREV_NEXT betterc, Better C, ob, Live Functions) )