r/C_Programming • u/thecratedigger_25 • Oct 22 '26
Question Has anyone ever tried out the TinyC compiler before?
Musl gcc is small but tinyc caught me eye due to how small it is and the fact that it can self host.
It supports C99 standards out of the box and it only takes up a few hundred kilobytes. I wonder if anyone tried it.
80
Upvotes
10
u/cKGunslinger Oct 22 '26
It's fast and best when used for fast compilation. It does not generate highly-optimized code, but it's amazing how often most things don't need to be highly optimized.
And I always forget if it's TCC or PCC that doesn't support thread-local storage. But I think it's TCC.
6
u/sciencekm Oct 23 '26
This is my goto compiler because it is very fast. I only switch to other compilers when it is time to build release/optimized binaries.
96
u/runningOverA Oct 22 '26
Written by the same author that wrote ffmpeg, quickjs, QEMU.
TinyC is used by some scripting languages to compile and then run the program in one go, making it feel like a scripting language while its not.
50
u/TheChief275 Oct 22 '26 edited Oct 23 '26
TCC is absolutely fantastic. One cute trick you could do is put this at the top of your C code:
and make it executable. This works (1) because # is treated as a comment in Shell/Bash script and exec replaces the process so the rest of the file doesn't get executed, and (2) because TCC is so incredibly fast at compiling (try it; it's unbelievably fast), running e.g. a Hello World C program this way will be faster than running one in Python.
Another thing I want to try for my next project is using TCC as a compiler backend, i.e. producing C code but also having TCC so you can also produce libraries/executables directly, which most compilers are still expected to do. Not sure how well this works, but the fast compilation time of TCC seems enticing here as a debug build option during development. Actual release builds could just be fed into GCC or Clang separately
17
u/vectorj Oct 22 '26 edited Oct 22 '26
For what it’s worth, I’ve seen YouTube/twitch Tsoding use tinyc, including changing tinyc itself. Worth a watch.
14
u/chibuku_chauya Oct 22 '26
Yes, I use TCC. It’s *fast*. An engineering marvel.
26
u/kansetsupanikku Oct 22 '26
I think many people did. It is popular and the author is - deservedly so - a highly respected figure in the community. It can even be used to build Linux from source on boot.
But the only reasonable use cases are ones where compilation speed is the primary objective. Or "compiler size", I guess, but that sounds highly atypical. TCC is not designed to optimize. The results just might make you realize how much the modern compilers are doing for you be default - as, in comparison, the performance is going to be kinda horrible.
1
u/xpusostomos Oct 24 '26
What architectures does it support?
1
u/KseandI Oct 27 '26
Tbh, I don't really like it. I know using freestanding mode in OS environment isn't a great idea, but if mainstream compilers can at least do something there, tcc just can't. Its
__asm__directive has many problems with r8-r15 registers selection on amd64, both in inline assembly and register selector for variables (but at least you can write register loading by hand because optimization is non-existent there and your code written by hand will probably be even faster than tcc's prologue). And va_begin builtin is always an intrinsic on all compilers expect on tcc, where it's a standard function for some reason, that won't link in freestanding mode and that depends on memset with abort from libc. All of these problems are mostly C being uncertain, but I still find it frustrating more on tcc.3
u/LordRybec Oct 23 '26
Haven't used it yet, but I'm looking into trying to setup an extremely bare bones dev system on a low resource microcontroller, and this was suggested by AI, since GCC uses too much memory for my target system.
The main downsides with TinyC is lack of optimization and advanced compiler extensions. GCC has extensions that can do pretty cool things (optimizations and more, for example, GCC has anonymous unions in C99 (if you don't enable strict mode), which weren't officially added to C until C11), and it goes through multiple compile steps to allow for advanced optimization. TinyC is a single pass compiler, which makes it fast and low memory, but it doesn't produce optimal machine code.
For applications where there are enough resources, I'd use GCC, but for resource constrained environments, TinyC seems like a really good option.
2
u/pedersenk Oct 23 '26
I use the TinyC combined busybox often for some of my embedded Linux projects. Absolutely fantastic.
The one disadvantage of TinyC is that not too many architectures are supported.
2
u/montymole123 Oct 23 '26
It claims to support C89 fully. Supports only some features of C99. I'm impressed it supports passing and returning structs from functions many stripped down C compilers don't
1
u/Evil-Twin-Skippy Oct 23 '26
There is actually an extension to the Tcl language that uses tinycc to compile extensions for the language inside the language.
1
u/wak6817-2 29d ago
I tried it and for me; IT'S PERFECT
1
u/JoK3rOp Oct 23 '26
Chibiccnkooks better than tinyc according to tsoding. I've not used it personally thought.
-2
u/FransFaase Oct 22 '26
As someone who wrote a C compiler to compile TCC, I can say that the code is its own unit test, as it contains many edge cases, such as goto's inside switch statement and an obscure memory allocator returning memory at 32 bit boundaries for 64 bit targets. TCC 0.9.26/27 do not support 64 targets by default. Some patches are needed. TCC is not an example of quality code.