ArticleslgStudy

computer science

Tiny C Compiler

Tiny C Compiler is a computer science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Tiny C Compiler rather than just read about it. In short: The Tiny C Compiler, TCC, tCc, or TinyCC is a C compiler targeting x86 (32-bits), x86-64 and ARM initially written by Fabrice Bellard. It is designed to work for slower computers with little disk space (e.g. on rescue disks).

Tiny C Compiler — main illustration
Tiny C Compiler — illustration

Key takeaways

  • Tiny C Compiler belongs to computer science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Tiny C Compiler to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Tiny C Compiler from memory before moving on to harder problems.

Reference excerpt

The Tiny C Compiler, TCC, tCc, or TinyCC is a C compiler targeting x86 (32-bits), x86-64 and ARM initially written by Fabrice Bellard. It is designed to work for slower computers with little disk space (e.g. on rescue disks). Windows operating system support was added in version 0.9.23 (17 June 2005). TCC is distributed under the GNU Lesser General Public License. TCC claims to implement all of ANSI C (C89/C90), much of the C99 ISO standard, and many GNU C extensions including inline assembly.

Features TCC has a number of features that differentiate it from other current C compilers:

Its small file size (about 100 KB for the x86 TCC executable) and memory footprint allow it to be used directly from a single 1.44 M floppy disk, such as a rescue disk. TCC is intended to produce native x86, x86-64 and ARM code very quickly; according to Bellard, it compiles, assembles and links about nine times faster than GCC does. As of 2023, the "mob" development branch also includes support for RISC-V and TMS320C67xx (a DSP chip). TCC has a number of compiler-specific language features intended to improve its practicality, such as an optional memory and bound checker, for improved code stability. TCC allows programs to be run automatically at compile time using a command-line switch. This allows programs to be run as a shell script under Unix-like systems that support the shebang interpreter directive syntax. The shebang for TCC (as given on the official TCC website) is #!/usr/local/bin/tcc -run (assuming TCC is installed to /usr/local/bin/tcc, the location of installation may vary according to system).

Compiled program performance In general, TCC's implementation emphasizes smallness instead of optimally-performing results. TCC generates code in a single pass, and does not perform most of the optimizations performed by other compilers. TCC compiles every statement on its own, and at the end of each statement register values are written back to the stack and must be re-read even if the next line uses the values in registers (creating extraneous save/load pairs between statements). TCC uses only some of the available registers (e.g., on x86 it never uses ebx, esi, or edi because they need to be preserved across function calls). TCC performs a few optimizations, such as constant propagation for all operations, multiplications and divisions are optimized to shifts when appropriate, and comparison operators are specially optimized (by maintaining a special cache for the processor flags). It also does some simple register allocation, which prevents many extraneous save/load pairs inside a single statement. Here are two benchmark examples:

A recursive Fibonacci algorithm on a 1.8 GHz Intel Centrino laptop with 512 MB RAM yields a noticeable difference in results between Microsoft Visual C++ compiler 13.10.3052 and TCC. To calculate the 49th Fibonacci number, it took a MS Visual C++ program approximately 18% longer than the TCC compiled program. A test compared different C compilers by using them to compile the GNU C Compiler (GCC) itself, and then using the resulting compilers to compile GCC again. Compared to GCC 3.4.2, a TCC modified to compile GCC was able to compile the compiler ten times faster, but the resulting .exe it produced was 57% larger, and much slower, taking 2.2 times as long to compile GCC again.The results were: Running cc1 (the GCC C compiler) on itself required 518 seconds when compiled using GCC 3.4.2, 545 seconds using Microsoft C compiler, and 1145 seconds using TCC. To create these compilers in the first place, GCC (3.4.2) took 744 seconds to compile the GCC compiler, whereas TCC took only 73 seconds. The level of optimization in each compiler was -O1 or similar.

Uses TCCBOOT, a hack where TCC loads and boots a Linux kernel from source in about 10 seconds. That is to say, it is a "boot loader" that reads Linux kernel source code from disk, writes executable instructions to memory, and begins running it. This did require changes to the Linux build process. TCC has been used to compile GCC, though various patches were required to make this work. TCC was used to demonstrate a defense against the trust attack. It is also used in GNU Guix in an attempt to make the distribution bootstrappable without using any binary. Cinpy is a Python library that allows you to implement functions with C in Python modules. The functions are compiled with TCC at runtime. The results are made callable in Python through the ctypes library. TCC has been used as a reference for the compiled version of the Super Micro-Max Chess program source. Bun uses TCC to expose an API which allows users to compile and run C programs from JavaScript.

History TCC has its origins in the Obfuscated Tiny C Compiler (OTCC), a program Bellard wrote to win the International Obfuscated C Code Contest (IOCCC) in 2001. After that time, Bellard expanded and deobfuscated the program to produce tcc. At some time prior to 4 February 2012 Fabrice Bellard updated the project's official web page to report that he was no longer working on TCC. Since Bellard's departure from the project, various people and groups have distributed patches or maintained forks of TCC to build upon or fix issues with TCC. This includes Dave Dodge's collection of unofficial tcc patches, Debian and kfreebsd downstream patches, and grischka's gcc patches. Grischka also set up a public Git repository for the project that contains a mob branch where numerous contributions, including a shared build, cross-compilers, and SELinux compatibility were added. Grischka's GIT repository later became the official TCC repository (linked to by Fabrice Bellard's Savannah project page).

Current status As of December 2017 both the official TCC mailing list and the official Git repository (as linked to by Fabrice Bellard's GNU Savannah project page) show active discussion and development by many developers and interested users. In December 2017, grischka announced on the mailing list that TCC version 0.9.27 was released.

See also

GNU Compiler Collection Portable C Compiler (PCC) LCC (compiler) Small-C Small Device C Compiler (SDCC) Open Watcom C/C++ - open source x86 C/C++/Fortran compiler for DOS, OS/2, Windows, Linux

References

External links TCC's active mailing list PTSource IDE-Integrated Development Environment includes TCC.

Illustrations

Tiny C Compiler illustration

Worked examples

Example 1 — a first encounter with Tiny C Compiler

Start with the simplest possible case. Write down what Tiny C Compiler claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In computer science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Tiny C Compiler before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Tiny C Compiler ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Tiny C Compiler

In research
Tiny C Compiler appears in computer science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Tiny C Compiler in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Tiny C Compiler is common in secondary-school and first-year university syllabi. It links to neighbouring topics C (programming language) compilers, Free and open source compilers, Free software programmed in C, so understanding it makes those chapters shorter.
In everyday life
Look for Tiny C Compiler outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “Tiny C Compiler” →

How to study Tiny C Compiler in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Tiny C Compiler means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Tiny C Compiler out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Tiny C Compiler in simple terms?

The Tiny C Compiler, TCC, tCc, or TinyCC is a C compiler targeting x86 (32-bits), x86-64 and ARM initially written by Fabrice Bellard. It is designed to work for slower computers with little disk space (e.g. on rescue disks).

Why does Tiny C Compiler matter?

Because it connects several computer science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Tiny C Compiler?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Tiny C Compiler.

Tags

  • C (programming language) compilers
  • Free and open source compilers
  • Free software programmed in C
  • Software programmed in assembly language
  • Software using the GNU Lesser General Public License

Keep exploring