Zig NEWS

Discussion on: Understanding comptime var

Collapse
 
kristoff profile image
Loris Cro

Now it isn't clear to me what the restriction on read is (someone please explain in comments if you do), given that reads do not change the value of the variable and it should be safe to to read this value during compile time AND runtime.

I think the intended meaning is that during comptime the variable can be mutated and referring to it means that you will read from it its current value (which might change during as the comptime evaluation progresses). At runtime the value of the variable is fixed as it has been finalized during comptime, so all references to it are implicitly replaced with the value of the variable.

In other words, a comptime var variable is const at runtime.