D is the best tool for this!!! How do we tell them??

Guillaume Piolat guillaume.piolat at gmail.com
Sun Aug 4 10:06:47 UTC 2024


On Saturday, 3 August 2024 at 18:52:42 UTC, Emmanuel wrote:
> https://www.theregister.com/2024/08/03/darpa_c_to_rust/#:~:text=The%20term%20stands%20for%20TRanslating,do%20so%20is%20memory%20safety.
>
>
> the DARPA project wants to translate all their legacy C code to 
> Rust. they prefer using a programming language which will 
> reject unsafe programs at compile times.
>
> maybe one PULL request from the D community can???? showing how 
> good D is for a job like this!!

 From translating heaps of C to D: it's not that easy sometimes.

- Some C headers like j40.h and miniz.h use the "switch-based 
coroutine" and exploit the fact the case label can be anywhere to 
create push parsers. Rust match doesn't allow labels anywhere, 
but D does so you can do the switch-based coroutine. Example: 
https://gist.github.com/mrtrizer/a14c033a054c191d9d23bfa516ad8107
At least this case is easy in D.

- Some C headers like j40.h and stb_image_resize2.h use header 
self-include to change macros and have some sort of templates. A 
single C header can include itself many times (imagine the poor 
lexer). When translating this, it can be tempting to just expand 
however the translated code may make more sense if done with a 
policy-based template and `mixin`.






More information about the Digitalmars-d mailing list