Covert a complex C header to D

Nicholas Wilson via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed Apr 5 05:41:09 PDT 2017


On Wednesday, 5 April 2017 at 12:27:23 UTC, biocyberman wrote:
> On Monday, 3 April 2017 at 23:10:49 UTC, Stefan Koch wrote:
>> On Monday, 3 April 2017 at 11:18:21 UTC, Nicholas Wilson wrote:
>>>    prefer template over string mixins where possible. This 
>>> will make the code much more readable.
>>
>> My advise would be the opposite.
>> templates put much more pressure on the compiler then 
>> string-mixins do.
>> Also the code that templates expand to is hard to get.
>> Whereas the code that string mixins expand to can always be 
>> printed one way or another.
>
> Could you elaborate more about this (i.e. show where mixins is 
> more readable, debugable and less stressful to the compiler)  ? 
> This kind of information is good for tuning stage later. My 
> goal now is to finish the conversion and running of the header 
> and the test code 
> (https://github.com/attractivechaos/klib/blob/master/test/khash_test.c).
>
> @Ali:
> I noticed the -E option recently but haven't really used it. I 
> now generated the pre-processed source and try to make use of 
> it.

While Stefan correctly notes that templates are slower than 
string mixins I generally find templates easier to read.
In terms of debugability:
you can pragma(msg, myGeneratedString) to see the generated code;
the error messages you get from templates are slightly more 
difficult to read than normal error messages in that you have to 
figure out what the significance of a particular parameter is (is 
it missing a method or operator? is it a struct instead of a 
class?), properly constraining the templates helps with this 
although the compiler is usually pretty good.


More information about the Digitalmars-d-learn mailing list