Tool to convert (translate) C to Go?

user811773 picture user811773 · Jan 9, 2012 · Viewed 14k times · Source

What tool to use to convert C source code into Go source code?

For example, if the C code contains:

struct Node {
    struct Node *left, *right;
    void        *data;
};

char charAt(char *s, int i) {
    return s[i];
}

the corresponding Go code generated by the tool should be:

type Node struct {
    left, right *Node
    data        interface{}
}

func charAt(s string, i int) byte {
    return s[i]
}

The tool does not need to be perfect. It is OK if some parts of the generated Go code need to be corrected by hand.

Answer

Joshua picture Joshua · Oct 7, 2012

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.