View Code? Open in Web Editor
NEW
This project forked from goplus/c2go
Convert C to Go
License: Apache License 2.0
c2go's Introduction
c2go - Convert C to Go
How to run examples?
- Build c2go tools:
go install -v ./...
- Go
testdata/xxx
directory, and run c2go .
What's our plan?
- First, Support most of the syntax of C. Stage:
Finished Almost
, see Supported C syntax.
- Second, Support most of C standard libaries, and can import them by Go+. Stage:
Doing
.
- Last, Support all custom libraries, especially those well-known open source libraries. Stage:
Planning
.
Supported C syntax
Data structures
Operators
- Arithmetic: a+b, a-b, a*b, a/b, a%b, -a, +a
- Increment/Decrement: a++, a--, ++a, --a
- Comparison: a<b, a<=b, a>b, a>=b, a==b, a!=b
- Logical: a&&b, a||b, !a
- Bitwise: a|b, a&b, a^b, ~a, a<<n, a>>n
- Pointer Arithmetic: p+n, p-n, p-q, p++, p--
- Assignment:
=
- Operator Assignment: a
<op>=
b
- BitField Assignment:
=
- BitField Operator Assignment: a
<op>=
b
- Struct/Union/BitField Member: a.b
- Array Member: a[n]
- Pointer Member: &a, *p, p[n], p->b
- Comma:
a,b
- Ternary Conditional: cond?a:b
- Function Call: f(a1, a2, ...)
- Conversion: (T)a
- Sizeof: sizeof(T), sizeof(a)
Literals
Initialization
- Basic:
T a = expr
- Array:
T[] a = { expr1, expr2, ... }
, T[N] a = { expr1, expr2, ... }
- Struct:
struct T a = { expr1, expr2, ... }
, struct T a = { .a = expr1, .b = expr2, ... }
- Union:
union T a = { expr }, union T a = { .a = expr }
- Array in Struct:
struct { T[N] a; ... } v = { { expr1, expr2, ... }, ... }
, struct { T[N] a; ... } v = { { [0].a = expr1, [1].a = expr2, ... }, ... }
Control structures
Functions
c2go's People
Contributors