Add ImportC compiler to dmd

Walter Bright newshound2 at digitalmars.com
Mon May 10 03:13:51 UTC 2021


On 5/9/2021 7:12 PM, Adam D. Ruppe wrote:
> On Monday, 10 May 2021 at 01:45:22 UTC, Walter Bright wrote:
>> 11. C++ can compile C code, which is a ginormous advantage for C++. Can we 
>> afford not to do that?
> 
> You want to fully compile the C code, not just extract bindings to link to it?

Yes. Frankly, there's no reason not to once you've done nearly all the work 
anyway. (For example, to evaluate static array dimensions, an expression parser 
is needed.)


> There's a lot of convenience to that - I've translated many lines of code from C 
> to D by hand (a pretty easy process btw, just tedious, but if you sit down for a 
> few hours and just do it, it is a result you can use for years to come) to take 
> advantage of the convenience; being able to dmd -i is nice.

Yeah, I did the backend conversion from C to D. It took a couple hours per file, 
most of the tedium came from it being terribly written code.


> But I think the binding aspect is a lot more important and without the 
> preprocessor part you just can't do that. It is an absolute must for this to be 
> useful.

I do have a forlorn hope that some C users will find it useful to replace many 
of their macros with enum, const, and inline function declarations.


> If you can get some of that #define stuff to just work, then maybe we can merge 
> this and iterate on it from there.
> 
> But I'm against merging something that's only maybe 20% done. Get up to 50% - 
> integrated cpp with those #defines actually being available to D... and maybe we 
> have something usable and a solid basis to estimate how much work is left (by 
> the time you get to the point where you can do this, the work is about 1/3 done. 
> There'd still the all the little details that need to be done and the inevitable 
> flurry of bugs. I'd be surprised if this is legitimately usable by the end of 
> the year. But it would prove it is realistically possible once importing a 
> module with some defined constants works from the D side.)

The trouble is making it fully functional will require tweaks all over the D 
semantic code. Constantly needing to rebase this large code base for a year is 
an unpleasant prospect.

Besides, ImportC is simply not going to break any existing functionality, so 
people can just ignore it successfully.



More information about the Digitalmars-d mailing list