#include C headers in D code

Nemanja Boric 4burgos at gmail.com
Thu Apr 12 12:38:23 UTC 2018


On Thursday, 12 April 2018 at 11:43:51 UTC, John Colvin wrote:
> On Wednesday, 11 April 2018 at 18:36:56 UTC, Walter Bright 
> wrote:
>> On 4/11/2018 3:25 AM, Atila Neves wrote:
>>> [...]
>>
>>
>> That's right. There is no general solution. One can only look 
>> for common patterns and do those. For example,
>>
>>   #define X 15
>>
>> is a common pattern and can be reliably rewritten as:
>>
>>   enum X = 15;
>
> If I understand it correctly, dpp doesn't do that.
>
> Instead, it runs the pre-processor on the source code, just 
> like in C, so
>
> // test.dpp
> #define X 15
> int foo() { return X; }
>
> becomes
>
> // test.d
> int foo() { return 15; }
>
> The upside of this approach: all macros just work, unless they 
> use C (not C pre-processor, C proper) features that dpp can't 
> handle. `sizeof(...)` is a special case that is handled in 
> dpp.cursor.macro.translateToD and more could be added.
>
> The downside: macros can't be directly used outside .dpp files.

Yes, I assumed it actually "expands" the macros, whereas it 
actually runs
the preprocessor on dpp files: 
https://github.com/atilaneves/dpp/issues/30

I can see it perfectly matches the Atila's usecase, and I'm 
curious
what are the other usecases for dpp?


More information about the Digitalmars-d-announce mailing list