ImportC can now automatically run the preprocessor

Ali Çehreli acehreli at yahoo.com
Sun May 15 17:22:28 UTC 2022


On 5/15/22 08:44, Ola Fosheim Grøstad wrote:
 > On Sunday, 15 May 2022 at 14:57:36 UTC, Ali Çehreli wrote:
 >> More on topic, I am one of those who thinks ImportC is amazing and
 >> will be very useful. There is potential in it.
 >
 > Yes, there is potential, but can we agree that encouraging people to use
 > it (for other things than testing) is not a good idea until the feature
 > is complete? You risk killing off the potential by locking it down to a
 > premature design.

Agreed. This is a documentation bug: The following page should say "This 
feature is under construction.":

   https://dlang.org/spec/importc.html

At the moment it says "This document is under construction."

 >> The discovery of "modules for C" is unbelievable to me. It came only
 >> because one inventor thought an otherwise unrelated idea was worth
 >> pursuing.
 >
 > What is it? I've seen it mentioned, but I don't understand what it is
 > yet.

Walter explained the implementation of ImportC at this meetup:

   https://nwcpp.org/April-2022.html

He started from the point of view of the compiler writer, explaining 
symbol tables. Once a C file is parsed, it gets converted into a 
language-agnostic module. Once both D and C coexist as modules, they can 
interact as modules do. As a result, the following surprises emerge:

- C can import D
- C can call D struct constructors, destructors, .init, etc.
- C can import C (no more header files)
- Template instantiation from C
- Function overloads for C
- Introspection for C
- etc. (I can't think of right now what else may be hidden in there.)

The only requirement is to compile the C module with dmd.

I covered ImportC in a recent meetup but only Nicholas Wilson showed up 
and he and I had fun experiments with this feature:

   https://forum.dlang.org/thread/t0r1qn$2fnu$1@digitalmars.com

Our meeting was from the point of view of the user.

Ali



More information about the Digitalmars-d mailing list