3 ms·
The comptime keyword is only needed in Zig if the code could execute at runtime. It forces compile-time evaluation, but it isn't the only way for it to happen.
by samatman 2y ago
The comptime keyword is only needed in Zig if the code could execute at runtime. It forces compile-time evaluation, but it isn't the only way for it to happen.
So Zig actually does what you seem to think it should do (and I agree! it's great!): if something can be calculated at compile time, it is. Only when the compiler can't statically deduce a compile-time construct is it necessary to use the `comptime` keyword: in fact, it's an error to use the keyword when the context is already comptime.