> ## Documentation Index
> Fetch the complete documentation index at: https://mintlify.com/TinyCC/tinycc/llms.txt
> Use this file to discover all available pages before exploring further.

# Quick start

> Compile and run your first C program with TinyCC in under a minute

# Quick start

This guide will get you up and running with TinyCC in just a few steps. You'll learn how to compile and run C programs using TCC's unique direct execution feature.

> [!NOTE]
>
> Before starting, make sure you have [installed TinyCC](https://mintlify.com/TinyCC/tinycc/installation.md) on your system.

## Your first TCC program

Let's create and run a simple "Hello World" program using TCC.

**1. Create a C source file**

Create a file named `hello.c` with the following content:

```c hello.c theme={null}
#include <stdio.h>

int main()
{
    printf("Hello World\n");
    return 0;
}
```

**2. Compile and run directly**

TCC's killer feature is the ability to compile and execute in one step:

```bash theme={null}
tcc -run hello.c
```

Output:

```
Hello World
```

> [!TIP]
>
> The `-run` option compiles the code in memory and executes it immediately without creating an executable file. This is perfect for quick testing and scripting!

**3. Create an executable (optional)**

If you want to create a standalone executable:

```bash theme={null}
tcc hello.c -o hello
./hello
```

This creates a binary file named `hello` that you can run anytime.

## TCC as a C script interpreter

One of TCC's most powerful features is C scripting support. You can run C code like a shell script!

**1. Create a C script**

Create a file named `hello_script.c`:

```c hello_script.c theme={null}
#!/usr/local/bin/tcc -run
#include <stdio.h>

int main()
{
    printf("Hello from a C script!\n");
    return 0;
}
```

The first line is a shebang that tells your shell to use TCC to run the file.

**2. Make it executable**

Set the execute permission:

```bash theme={null}
chmod +x hello_script.c
```

**3. Run it directly**

Now you can run it like any shell script:

```bash theme={null}
./hello_script.c
```

Output:

```
Hello from a C script!
```

> [!NOTE]
>
> If TCC is installed in a different location on your system, adjust the shebang path accordingly. Use `which tcc` to find the correct path.

## Working with command line arguments

C scripts can accept command line arguments just like any other program:

```c args_demo.c theme={null}
#!/usr/local/bin/tcc -run
#include <stdio.h>

int main(int argc, char **argv)
{
    printf("Program name: %s\n", argv[0]);
    printf("Number of arguments: %d\n\n", argc - 1);
    
    for (int i = 1; i < argc; i++) {
        printf("Argument %d: %s\n", i, argv[i]);
    }
    
    return 0;
}
```

```bash Using -run theme={null}
tcc -run args_demo.c hello world 123
```

```bash As a script theme={null}
chmod +x args_demo.c
./args_demo.c hello world 123
```

Output:

```text theme={null}
Program name: args_demo.c
Number of arguments: 3

Argument 1: hello
Argument 2: world
Argument 3: 123
```

## Compiling multiple files

TCC can compile and link multiple C files together:

**1. Create a utility module**

Create `utils.c`:

```c utils.c theme={null}
#include <stdio.h>

void greet(const char *name)
{
    printf("Hello, %s!\n", name);
}
```

And its header `utils.h`:

```c utils.h theme={null}
#ifndef UTILS_H
#define UTILS_H

void greet(const char *name);

#endif
```

**2. Create the main program**

Create `main.c`:

```c main.c theme={null}
#include "utils.h"

int main()
{
    greet("TinyCC");
    return 0;
}
```

**3. Compile and run**

Compile both files together:

```bash Direct execution theme={null}
tcc -run main.c utils.c
```

```bash Create executable theme={null}
tcc main.c utils.c -o myprogram
./myprogram
```

Output:

```text theme={null}
Hello, TinyCC!
```

## Using TinyCC's built-in library

TCC includes a minimal library `tcclib.h` that's perfect for small programs or systems without standard headers:

```c minimal.c theme={null}
#!/usr/local/bin/tcc -run
#include <tcclib.h>

int main()
{
    printf("Hello World\n");
    return 0;
}
```

> [!TIP]
>
> Using `<tcclib.h>` instead of `<stdio.h>` results in faster compilation times. It's especially useful for floppy disk or embedded environments where space is limited.

## Compiling from stdin

TCC can read and compile C code from standard input, which is great for one-liners and testing:

```bash theme={null}
echo 'main(){puts("hello");}' | tcc -run -
```

Output:

```text theme={null}
hello
```

This technique is useful for quick experiments and integrating with shell pipelines.

## Common compilation patterns

```bash Compile and run theme={null}
tcc -run program.c
```

```bash Create executable theme={null}
tcc program.c -o program
```

```bash Compile to object file theme={null}
tcc -c program.c
# Creates program.o
```

```bash Link object files theme={null}
tcc file1.o file2.o -o program
```

```bash Multiple source files theme={null}
tcc main.c utils.c helper.c -o program
```

```bash With include path theme={null}
tcc -I./include program.c -o program
```

```bash With library theme={null}
tcc program.c -lm -o program
# Links with math library
```

## Comparing TCC with GCC

Here's how TCC commands compare to GCC:

| Task | TCC | GCC |
| - | - | - |
| Compile and run | `tcc -run hello.c` | `gcc hello.c -o hello && ./hello` |
| Create executable | `tcc hello.c -o hello` | `gcc hello.c -o hello` |
| Compile to object | `tcc -c hello.c` | `gcc -c hello.c` |
| Show version | `tcc -v` | `gcc --version` |
| Verbose output | `tcc -vv` | `gcc -v` |

> [!WARNING]
>
> TCC optimizes for compilation speed, not runtime performance. For production code where runtime speed matters, consider using GCC or Clang with optimization flags like `-O2` or `-O3`.

## Benchmarking compilation speed

See the difference in compilation speed:

```bash theme={null}
# TCC with benchmark
tcc -bench hello.c -o hello

# Compare with GCC
time gcc -O0 hello.c -o hello_gcc
time tcc hello.c -o hello_tcc
```

TCC typically compiles **9-10 times faster** than GCC with `-O0` (no optimization).

## Next steps

> **[Command line reference](https://mintlify.com/TinyCC/tinycc/cli/command-reference.md)**
>
> Learn about all TCC command line options and flags

> **[C scripting guide](https://mintlify.com/TinyCC/tinycc/cli/scripting.md)**
>
> Master advanced C scripting techniques with TCC

> **[libtcc API](https://mintlify.com/TinyCC/tinycc/api/overview.md)**
>
> Use TCC as a library for dynamic code generation

> **[Features](https://mintlify.com/TinyCC/tinycc/features/c-language-support.md)**
>
> Explore TCC features and capabilities

> [!TIP]
>
> Try using TCC for your daily C development tasks. The instant compilation feedback makes it great for learning C, testing algorithms, and rapid prototyping.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.