-
Book Overview & Buying
-
Table Of Contents
-
Feedback & Rating
Learning Zig
By :
Alright, so you’ve been living dangerously, dabbling with undefined variables. Maybe you’ve even thought, “Hey, it’s just uninitialized, how bad could it be?” Well, let’s just say you’re playing with fire—but in Debug Mode, Zig gives you a fire extinguisher.
When you run your code in Debug Mode, Zig catches your use of undefined by filling it with a special byte pattern: 0xaa. This isn’t just for fun. This pattern helps you spot when you’re working with uninitialized memory. It’s like a neon sign saying, "Hey, you forgot to set this variable!"
Let’s walk through how you can observe this behavior in action.
We’ll declare a variable using undefined and print its value. In Debug Mode, Zig will fill the uninitialized variable with the special 0xaa byte pattern:
const print = @import("std").debug.print;
pub fn main...