Compile-time table
A table of squares computed by the compiler with a translate-time program.
+ <stdio.h>
# Runs while compiling: the table below is computed by the compiler, not at run time.
@tt
vals:=[]
for i 0..8
vals = push(vals, str(i * i))
emit("static const int squares[] = {" + join(vals, ", ") + "};")
f main()
for i := 0; i < 8; i++
printf("square %d = %d\n", i, squares[i])
< 0
#include <stdio.h>
static const int squares[] = {0, 1, 4, 9, 16, 25, 36, 49};
int main(void) {
for (int i = 0; i < 8; i++) {
printf("square %d = %d\n", i, squares[i]);
}
return 0;
}
Output
square 0 = 0
square 1 = 1
square 2 = 4
square 3 = 9
square 4 = 16
square 5 = 25
square 6 = 36
square 7 = 49
What it shows
@tt, emit