4 ms·
I had a great time implementing a C compiler and embedding it in the D compiler so it can import C code directly. I keep toying with the idea of doing that for
by WalterBright 4y ago
I had a great time implementing a C compiler and embedding it in the D compiler so it can import C code directly. I keep toying with the idea of doing that for C++, but since C++98 the language has just gotten too complicated to reliably map onto D semantics.
- humanrebar 4y agoI have been thinking of this D non-feature when reading up on the Carbon approach. Do you have any takes on how Carbon could be successful on mapping to C++ when D considers it too much of a reach?
- WalterBright 4y agoI don't know anything about Carbon. But a reasonable approach would be to use an existing C++ compiler and intercept its ASTs.
- Decabytes 4y agowith import C what is the benefit of creating bindings to C libraries if you can just work with the C code directly?
- WalterBright 4y agoImportC can handle the .h files and/or the .c files, as the user prefers.
- schveiguy 4y agoimport C is not perfect. There are pieces of C that don't map directly to D. Such as #define constants and macros. That being said, it will make writing bindings a LOT easier, even though D already has direct binding to C functions.