ImportC can now automatically run the preprocessor

Walter Bright newshound2 at digitalmars.com
Mon May 16 03:12:47 UTC 2022


On 5/15/2022 6:41 PM, Adam D Ruppe wrote:
> On Monday, 16 May 2022 at 01:05:33 UTC, Walter Bright wrote:
>> But what is missing is a compelling use case for it?
> 
> It is the only way I've seen that would let you ACTUALLY use full C APIs.

This is replacing C #define's with D constructions, right?

You're right, ImportC does not do that at the moment. However, it's always been 
the plan for it to gather up all the #define's, and replace the ones that can be 
replaced with D constructs, and ignore the rest.

I'm not going to pretend this can ever be a complete 100% solution, after all:

     #define BEGIN {
     #define END }

What can one do with that? Phooey.

I've talked with Atila about how dpp handles it. dpp looks for general patterns, 
and replaces those with generic D constructs. Atila (always the pragmatist) also 
programmed in specific replacements for specific #defines that appear in popular 
.h files. This is indeed an endless game of whack-a-mole, but it works, and it 
gets the job done.

I intend to leverage Atila's work for ImportC to do the same thing.

(It also may be possible to make these specific patterns something that users 
can contribute to, so they don't have to wait for the compiler team.)

But I still don't understand - why mixin this stuff? Why would someone want to 
type C code into a D source file?


More information about the Digitalmars-d mailing list