Some questions about porting code from C to BetterC

Dennis dkorpel at gmail.com
Tue Nov 30 23:22:11 UTC 2021


On Tuesday, 30 November 2021 at 21:05:46 UTC, Bagomot wrote:
> The for some errors are not clear to me. Write if you have 
> comments or ideas.

First impressions:
- You can use `extern(C): version(Posix):` to reduce the 
indentation level
- You're casting away `const` a lot, even when it's not necessary
- I skimmed through it in case anything stood out, but "here's 
1200 lines of code, there's some error in it" is a bit of a tough 
assignment :p

Here's the safest way to translate C code:

- Translate the header to D and call the original C code from D, 
verify that it works
- Incrementally remove functions from the C code and provide a 
translated D implementation for them instead. Verify that the 
code still works after each step, so you can find translation 
errors early.
- Once all C functions are translated, you can throw away the D 
header and stop linking with the C code, you're done!

Translating it all in one bunch might be faster if you pull it 
off, but then you run the risk of getting into the situation you 
are in right now, and then you have to debug.


More information about the Digitalmars-d mailing list