Examples
Every example is compiled to C by the real compiler, built with your C compiler and run while this site is generated, so the output shown is real.
- Hello, worldThe smallest NanoC program: an include, a function without braces and an implicit result.
- FizzBuzzClassic FizzBuzz with early returns, elif chains and a const char pointer result.
- Loops and Collatzfor and while loops with break and continue words, plus a Collatz step counter.
- Compact CPreprocessor chains, defines, early returns and conditional blocks without braces.
- Structs and enumsEnums, structs, arrays of records and a function returning a double.
- Fixed-width typesFixed-width integers, inttypes formats, a struct shorthand and gcd.
- Linked listA singly linked list with malloc and free, written with compact pointer syntax.
- Sorting with callbacksqsort with a comparison function pointer over an array of structs.
- Bitset sieveA sieve of Eratosthenes over a bit array using function-like defines.
- Token macrosHygienic-style token templates: max, clamp and generated getter functions.
- Generic vectorOne macro generates a typed growable vector per element type: generics without a runtime.
- Scoped cleanupA with-file block macro that always closes the file: RAII in one macro.
- Compile-time tableA table of squares computed by the compiler with a translate-time program.
- Prime table at translate timeThe compiler sieves the primes below 60 and emits a constant array and a count.
- Enum and name tableAn enum and its string table generated from one list, so they cannot drift apart.
- C interopRaw C islands next to NanoC code: call libm and your own C helper functions.
Open any example in the playground to edit it and see the C change as you type.