xxxxxxxxxx
// This is an equivalent program to 06, but written using CIR compile-time
// functions.
#include <cir.h>
#include <cirq.h>
int printf(const char *, ...);
static CirCodeId repeat(int n, CirCodeId code) {
return @CirQ(({
for (int i = 0; i < @CirAQ(n); i = i + 1)
@CirAQ(code);
}));
}
int main(void) {
int i = 20;
@repeat(3, printf("The value of i is %d\n", i));
return 0;
// If you squint carefully at the CIR output, you will see that CIR will treat
// the two `i` variables as two different variables.
//
// The CIR output, when compiled, will give the correct output:
// The value of i is 20