221V 18 hours ago
parent
commit
7217512afd
1 changed files with 32 additions and 31 deletions
  1. 32 31
      exercises/067_comptime2.zig

+ 32 - 31
exercises/067_comptime2.zig

@@ -30,35 +30,36 @@
 //
 const print = @import("std").debug.print;
 
-pub fn main() void {
-    //
-    // In this contrived example, we've decided to allocate some
-    // arrays using a variable count! But something's missing...
-    //
-    var count = 0;
-
-    count += 1;
-    const a1: [count]u8 = .{'A'} ** count;
-
-    count += 1;
-    const a2: [count]u8 = .{'B'} ** count;
-
-    count += 1;
-    const a3: [count]u8 = .{'C'} ** count;
-
-    count += 1;
-    const a4: [count]u8 = .{'D'} ** count;
-
-    print("{s} {s} {s} {s}\n", .{ a1, a2, a3, a4 });
-
-    // Builtin BONUS!
-    //
-    // The @compileLog() builtin is like a print statement that
-    // ONLY operates at compile time. The Zig compiler treats
-    // @compileLog() calls as errors, so you'll want to use them
-    // temporarily to debug compile time logic.
-    //
-    // Try uncommenting this line and playing around with it
-    // (copy it, move it) to see what it does:
-    //@compileLog("Count at compile time: ", count);
+pub fn main() void{
+  //
+  // In this contrived example, we've decided to allocate some
+  // arrays using a variable count! But something's missing...
+  //
+  comptime var count = 0;
+  
+  count += 1;
+  const a1: [count]u8 = .{'A'} ** count;
+  
+  count += 1;
+  const a2: [count]u8 = .{'B'} ** count;
+  
+  count += 1;
+  const a3: [count]u8 = .{'C'} ** count;
+  
+  count += 1;
+  const a4: [count]u8 = .{'D'} ** count;
+  
+  print("{s} {s} {s} {s}\n", .{ a1, a2, a3, a4 });
+  
+  // Builtin BONUS!
+  //
+  // The @compileLog() builtin is like a print statement that
+  // ONLY operates at compile time. The Zig compiler treats
+  // @compileLog() calls as errors, so you'll want to use them
+  // temporarily to debug compile time logic.
+  //
+  // Try uncommenting this line and playing around with it
+  // (copy it, move it) to see what it does:
+  //@compileLog("Count at compile time: ", count);
 }
+