I am attempting to convert a C program into Zig, but I keep getting an error saying:
fathoms.zig:3:19: error: unable to evaluate comptime expression
var feet: u32 = 6 * fathoms;
~~^~~~~~~~~
fathoms.zig:3:21: note: operation is runtime due to this operand
var feet: u32 = 6 * fathoms;
^~~~~~~
referenced by:
main: fathoms.zig:7:65
callMain: /home/jf/Installations/Ziglang/zig_lang/lib/std/start.zig:585:32
initEventLoopAndCallMain: /home/jf/Installations/Ziglang/zig_lang/lib/std/start.zig:519:34
callMainWithArgs: /home/jf/Installations/Ziglang/zig_lang/lib/std/start.zig:469:12
posixCallMainAndExit: /home/jf/Installations/Ziglang/zig_lang/lib/std/start.zig:425:39
_start: /home/jf/Installations/Ziglang/zig_lang/lib/std/start.zig:338:40
It is the translation from the C statement: feet = 6 * fathoms;
The error message didn’t write correctly in what I am guessing is a preview of this post.
Here is the code snippet:
const std = @import("std");
var fathoms: u32 = 2;
var feet: u32 = 6 * fathoms;
pub fn main() !void {
const stdout = std.io.getStdOut().writer();
try stdout.print("There are {d} feet in {d} fathoms!\n", .{ feet, fathoms });
// try stdout.print("Yes, I said {d} feet!\n", .{6 * fathoms});
}
Thanks to anyone who can help!