multiple-evalution-of-args-safe versions of repeat() { } and for_range() { } macros
[svn/Cll1h/.git] / demos / for_range.c
index 44a7b5be881d67ec3a7096e993b40dd8cd55412e..c96f24cb53b05768f55c127d1f1010f6246d05c5 100644 (file)
@@ -2,25 +2,50 @@
 
 program
 {
- int i;
+ int i,j=1;
 
- echo("for_range(i,0,1)");
- for_range(i,0,1) printf(" [%d]",i);
+ echo("Just plain vanilla auto-increment:\tfor_range(i,1,5)");
+ for_range(i,1,5)
+ {
+  printf(" [%d]",i);
+ }
  print("");
 
- echo("for_range(i,1,0)");
- for_range(i,1,0) printf(" [%d]",i);
+ echo("Single-evaluation of macro argument:\tj=1; for_range(i,0,j++)");
+ for_range(i,0,j++)
+ {
+  printf(" [%d]",i);
+ }
  print("");
 
- echo("for_range(i,1,1)");
- for_range(i,1,1) printf(" [%d]",i);
+ echo("Just plain vanilla auto-decrement:\tfor_range(i,1,0)");
+ for_range(i,1,0)
+ {
+  printf(" [%d]",i);
+ }
  print("");
 
- echo("for_range(i,1,5)");
- for_range(i,1,5) printf(" [%d]",i);
+ echo("Single iteration is possible too:\tfor_range(i,1,1)");
+ for_range(i,1,1)
+ {
+  printf(" [%d]",i);
+ }
  print("");
 
- echo("for_range(i,5,1)");
- for_range(i,5,1) printf(" [%d]",i);
+ echo("Yet another example of macro safety:\tj=2; for_range(i,5,--j)");
+ for_range(i,5,--j)
+ {
+  printf(" [%d]",i);
+ } 
+ print("");
+
+ echo("Nesting of this macro seems to be safe:\tfor_range(i,1,3) for_range(j,3,1)");
+ for_range(i,1,3)
+ {
+  for_range(j,3,1)
+  {
+   printf(" [%d,%d]",i,j);
+  }
+ }
  print("");
 }
This page took 0.185505 seconds and 4 git commands to generate.