D is our last hope

jmh530 john.michael.hall at gmail.com
Wed Dec 20 02:45:48 UTC 2023


On Tuesday, 19 December 2023 at 21:52:01 UTC, Adam D Ruppe wrote:
> On Tuesday, 19 December 2023 at 21:42:40 UTC, jmh530 wrote:
>> I understand that. My point was just that still hasn't been 
>> resolved.
>>
>> Steve suggested a separate import path flag for C imports. He 
>> explained
>
> I still say the best thing to do is to ditch the overloading of 
> the `import` keyword and instead embrace the `mixin` keyword.
>
> mixin[C](`#include<stdio.h>`);
>
> you can now use the full file name, with .h or .c or whatever 
> you want. And you can do this in context of D, meaning you can 
> do things like :
>
> @nogc {
>    mixin[C](`#include<stdio.h>`);
> }
>
>
> And potentially use macros:
>
> enum C_Context = mixin[C](`#define foo bar`);
> mixin[C, C_Context](`use foo here`);
>
> or something like that.

ImportC is a cool idea. It’s just got limitations right now that 
prevent it from being great. If rethinking it as mixin makes it 
smoother to use (does your idea resolve the duplicate symbol 
issue?), then it could make some sense.

I don’t know if it’s an either/or sort of thing, but I think you 
would need to introduce this with some sort of way to migrate 
existing importC code since importC wasn’t put behind a preview 
switch.

While you’re at it, a hypothetical D3 could have mixin[asm] and 
remove the asm block. You could also have `mixin[C/asm] template 
{}`.



More information about the Digitalmars-d mailing list