CIR Playground
Load example...
CIR on GitHub
Input
xxxxxxxxxx
 
1
// Welcome to CIR Playground!
2
//
3
// CIR is a compile-time evaluation and metaprogramming system
4
// for the C Programming Language. CIR Playground lets you try out CIR without
5
// the hassle of building and installing it on your computer.
6
//
7
// Let's start with a fibonacci function that is evaluated at compile time.
8
//
9
// Click "Run" to see the result!
10
​
11
#include <stdio.h>
12
​
13
static int fib(int n) {
14
    int a = 0, b = 1;
15
    for (int i = 0; i < n; i = i + 1) {
16
        int c = b;
17
        b = a + b;
18
        a = c;
19
    }
20
    return a;
21
}
22
​
23
int main(void) {
24
    // The use of @ evaluates fib(20) at compile time.
25
    // First, try running this program as-is by clicking "Run"!
26
    // Next, try removing the @, click "Run", and compare the result!
27
    printf("The answer is: %d\n", @fib(20));
28
    return 0;
29
}
30
​
stdout
1
 
1
​
stderr
1
 
1
​
Load Example...
    00 - Compile-time fibonacci 01 - Inline Repeat 02 - Compile-time strtok 03 - Does a code call a function 04 - C Preprocessor identifiers may be accidentally shadowed 05 - CIR identifiers won't be accidentally shadowed 06 - C Preprocessor accidental capture of symbols 07 - CIR won't accidentally capture symbols 08 - bf-to-C (low level ver) 09 - bf-to-C (with quote-antiquote) 10 - async-await 11 - Embed an external file 12 - zlib