#include C headers in D code
John Colvin
john.loughran.colvin at gmail.com
Thu Apr 12 11:43:51 UTC 2018
On Wednesday, 11 April 2018 at 18:36:56 UTC, Walter Bright wrote:
> On 4/11/2018 3:25 AM, Atila Neves wrote:
>> I did the best I could having seen some macros. It's likely
>> there are cases I've missed, or that maybe the translation in
>> the link above doesn't work even for what it's supposed to be
>> doing (I have no confidence about catching all the C casts for
>> instance).
>>
>> If there are other cases, I'll fix them as they're
>> encountered. It's possible some of them can't be fixed and the
>> user will have to work around them. Right now I have a feeling
>> it will probably be ok. Time will tell (assuming I have
>> users!).
>
>
> 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.
More information about the Digitalmars-d-announce
mailing list