Tool to convert (translate) C to Go?

I guess no such (C to Go source code conversion) tool exist today. You might consider to make your own converter. The question becomes: is it worth it, and how to do that?

It probably might not be worth the effort, because Go and C could be somehow interoperable. For example, if you use the GCC 4.6 (or to be released 4.7, i.e. the latest snapshot) your probably can link C & Go code together, with some care.

Of course, as usual, the evil is in the details.

If you want a converter, do you want the obtained Go code to be readable and editable (then the task is more difficult, since you want to keep the structure of the code, and you also want to keep the comments)? In that case, you probably need your own C parser (and it is a difficult task).

If you don't care about readability of the generated Go code, you could for example extend an existing compiler to do the work. For example, GCC is extensible thru plugins or thru MELT extensions, and you could customize GCC (with MELT, or your own C plugin for GCC) to transform Gimple representation (the main internal representation for instructions inside GCC) to unreadable Go code. This is somehow simpler (but still require more than a week of work).

Of course, Go interfaces, channels and even memory management (garbage collected memory) has no standard C counterpart.


rsc created github.com/rsc/c2go to convert the c based Go compiler into Go.

As an external example, akavel seems to be trying to use it to create a Go based lua: github.com/akavel/goluago/

github.com/xyproto/c2go is another project, but it hasn't been touched in a little while.