Skip to content
A small C11 compiler in C++11
C++ C CMake
Branch: master
Clone or download
Type Name Latest commit message Commit time
Failed to load latest commit information.
doc add Ken Thompson's Turing Award Lecture: Reflections on Trusting Trust Jan 25, 2019
example add chinese programming example Sep 22, 2016
include try supporting GNU extensions Oct 20, 2016
src Simplify useless dynamic allocation (#57) Jun 27, 2019
test switch build system from make to cmake (#53) Jan 31, 2019
.gitignore format code Nov 8, 2016
.travis.yml switch build system from make to cmake (#53) Jan 31, 2019
CMakeLists.txt change CMake minimum requirement to 2.8 Feb 1, 2019
LICENSE Create LICENSE Oct 21, 2016 support 996.ICU Mar 30, 2019

wgtcc Build Status

A small C11 compiler in C++11.


  1. x86-64
  2. linux 4.4.0
  3. clang 3.8.0 (or any version supports C++11)


$ cmake . -Bbuild
$ cd build && make && make test


$ make install

Then you can play with the examples:

$ wgtcc example/heart.c
$ wgtcc example/chinese.c


As wgtcc doesn't support PIC/PIE, if you are using gcc >= 6.2.0, specify -no-pie explicitly:

$ wgtcc -no-pie example/heart.c
$ wgtcc -no-pie example/chinese.c


wgtcc is aimed to implement the full C11 standard with some exceptions:

  1. Some features are supported only in grammar level(like keyword register).
  2. Features that disgusting me are removed (like default int type without type specifier).
  3. Some non standard GNU extensions are supported, but you should not rely on wgtcc of a full supporting.

Front End

A basic recursive descent parser

Back End

wgtcc generates code from AST directly. The algorithm is TOSCA (top of stack caching). It is far from generating efficient code, but at least it works and generates code efficently.

Memory Management

Through wgtcc was written in C++, I paid no effort for memory management except for a simple memory pool to accelerate allocations. only new is preferred because wgtcc runs fast and exits immediately after finishing parsing and generating code.


  1. Compilers Principles, Techniques and Tools. Second Edition.
  2. N1548, C11 standard draft
  3. 64-ia-32-architectures-software-developer-manual-325462
  4. 8cc
  5. 9c
  6. macro expansion algorithm


  • support GNU extensions (e.g. keyword __attribute__)
  • support variable length array
  • optimization (e.g. register allocation)
  • support type qualification
You can’t perform that action at this time.