Skip to main content
Bun includes TinyCC, a fast C compiler that can compile and execute C code at runtime. This is useful for high-performance computation, calling system APIs, and prototyping native code.

Basic Usage

Source Options

Inline Source

Source Files

Multiple Files

Headers and Includes

Standard Headers

TinyCC includes standard C library headers:

Custom Include Paths

Linking Libraries

System Libraries

Multiple Libraries

Library Search Paths

Preprocessor Defines

Compiler Flags

Optimization

Warnings

Multiple Flags

Symbol Types

See the FFI documentation for a complete list of supported types.

Common Patterns

Working with Arrays

Passing Arrays

Returning Arrays

Memory Management

Stack Allocation

Fast for small, short-lived data:

Heap Allocation

Required for large or long-lived data:

Real-World Examples

Fast Math

Image Processing

Sorting

Error Handling

Compile Errors

Runtime Errors

Performance

Compilation Speed

TinyCC is extremely fast:

Runtime Performance

Compiled code runs at native speed:

Limitations

TinyCC Constraints

  • No C++ support (C only)
  • Limited optimization (no -O3)
  • No inline assembly on some platforms
  • Smaller subset of GNU C extensions

Platform Support

  • macOS: x86_64, ARM64
  • Linux: x86_64, ARM64
  • Windows: x86_64 (limited)

Best Practices

  1. Check return values
  2. Free allocated memory
  3. Use const for read-only data
  4. Document ABIs

Debugging