Live data from Hacker News

C2Rust: translate C into Rust code

c2rust.com

1–10 of 79 posts

Re: C2Rust: translate C into Rust code

#6
post #2

How’s this compare to https://github.com/jameysharp/corrode

He doesn't appear to be a direct contributor, probably more of an inspiration. The only overlap I know of is that he also works/worked at Galois.

c2rust is written mostly in Rust, Python and C where as corrode was written in Haskell. The output of c2rust looks more like a literal projection from C into Rust, Corrode tried to limit the use of unsafe.

    $ tokei
    -------------------------------------------------------------------------------
     Language            Files        Lines         Code     Comments       Blanks
    -------------------------------------------------------------------------------
     Autoconf                4          199           85           56           58
     C                      88         6989         5175          754         1060
     C Header               21         2949         1497         1073          379
     CMake                   5           84           60           10           14
     C++                     5         3015         2320          295          400
     C++ Header              1          132          101            7           24
     Dockerfile              1           62           50            6            6
     HTML                    2           84           78            0            6
     Makefile                3           88           63            3           22
     Markdown               23         1482         1482            0            0
     Python                 26         6597         4988          319         1290
     Rust                  250        45111        35949         2893         6269
     Shell                  44          697          429          141          127
     Plain Text             15          555          555            0            0
     TOML                   11          197          148           24           25
     Vim Script              1          233          195            4           34
    -------------------------------------------------------------------------------
     Total                 500        68474        53175         5585         9714
    -------------------------------------------------------------------------------

Re: C2Rust: translate C into Rust code

#7
post #2

How’s this compare to https://github.com/jameysharp/corrode

(I'm one of the authors of this tool)

Our original plan was to simply work to improve Corrode. We eventually decided to to implement a new tool that uses Clang as the frontend in order to get more reliable parsing, preprocessing, and type checking of the input C code. The result is that we are able to support more code and C extensions than we thought we'd be able to building on top of the good work of the Corrode project.

Re: C2Rust: translate C into Rust code

#9
post #5

The insertion sort conversion example makes Rust look intimidating and verbose as compared to C :-).

I personally like more verbosity than one usually sees in C code. Explicitness is mostly a feature for me, though there needs to be a balance.

Re: C2Rust: translate C into Rust code

#10
post #5

The insertion sort conversion example makes Rust look intimidating and verbose as compared to C :-).

Fortunately, once you start refactoring the Rust to take advantage of the functionality that doesn't exist in C (like slices, iterators, etc), things start to look much cleaner.

Translating the code into ugly, unsafe Rust is intended to only be the first step. We're working on tools to help with that refactoring process, too.

Post reply on HN