Giter Club home page Giter Club logo

c2go's Introduction

c2go - Convert C to Go

Screen Shot1

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

  • Void: void
  • Boolean: bool
  • Integer: [signed/unsigned] [short/long/long long] int
  • Enum: enum
  • Float: float, double, long double
  • Character: [signed/unsigned] char
  • Wide Character: wchar_t
  • Large Integer: [signed/unsigned] __int128
  • Complex: _Complex float/double/long double
  • Typedef: typedef
  • Pointer: *T, T[]
  • Array: T[N], T[]
  • Array Pointer: T(*)[N]
  • Function Pointer: T (*)(T1, T2, ...)
  • Struct: struct
  • Union: union
  • BitField: intType :N

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

  • Boolean, Integer
  • Float, Complex Imaginary
  • Character, String
  • Array: (T[]){ expr1, expr2, ... }
  • Array Pointer: &(T[]){ expr1, expr2, ... }
  • Struct: struct T{ expr1, expr2, ... }

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

  • If: if (cond) stmt1 [else stmt2]
  • Switch: switch (tag) { case expr1: stmt1 case expr2: stmt2 default: stmtN }
  • For: for (init; cond; post) stmt
  • While: while (cond) stmt
  • Do While: do stmt while (cond)
  • Break/Continue: break, continue
  • Goto: goto label

Functions

  • Parameters
  • Variadic Parameters
  • Variadic Parameter Access
  • Return

c2go's People

Contributors

xushiwei avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.